BlackBerry Forums Support Community
              

Closed Thread
 
Thread Tools
Old 10-17-2009, 07:00 PM   #1
doni49
Thumbs Must Hurt
 
Join Date: Aug 2009
Model: Tour
PIN: N/A
Carrier: Verizon
Posts: 84
Default Persistent Data Problem

Please Login to Remove!

I'm trying to add my data to the Persistent store. When I run my app in the Simulator, I get JVM errors on the device.

But when I comment out the line that is marked in RED, I get no errors. Can someone PLEASE help me figure out why this isn't working?

TIA!

Code:
import java.util.Vector;
import java.lang.String;
import net.rim.device.api.ui.*;
import net.rim.device.api.ui.component.*;
import net.rim.device.api.ui.container.*;
import net.rim.device.api.ui.MenuItem;
import net.rim.device.api.system.*;
import net.rim.device.api.system.PersistentObject;
import net.rim.device.api.system.PersistentStore;

class Transaction{
	public Transaction(int ID, int Type, int Category, String Payee, double Amount){
		_id = ID;
		_type = Type;
		_category = Category;
		_payee = Payee;
		_amount = Amount;
	}
	public int getID(){
		return _id;
	}
	public int getType (){
		return _type;
	}
	public void setType(int Type){
		_type = Type;
	}
	public int getCategory(){
		return _category;
	}
	public void setCategory(int Category){
		_category = Category;
	}
	public String getPayee(){
		return _payee;
	}
	public void setPayee(String payee){
		_payee = payee;
	}
	public double getAmount(){
		return _amount;
	}
	public void setAmount(double amount){
		_amount = amount;
	}
	
	private int _id;
	private int _type;
	private int _category;
	private String _payee;
	private double _amount;
}
class CashBoxApp extends UiApplication
{
    static Vector Transactions;
    static PersistentObject persistTransactions;
    {
        Transactions = (Vector) persistTransactions.getContents();
        if( Transactions == null ) {
            Transactions = new Vector();
            persistTransactions.setContents( Transactions );
            persistTransactions.commit();
        }
    }
    static void addTransaction(Transaction a){
        Transactions.addElement(a);
        persistTransactions.commit();
    }
    public static void main(String[] args){
		
	addTransaction(new Transaction(1, 1, 2, "Dr. T - 1", 25.55));

	CashBoxApp app = new CashBoxApp();
        app.enterEventDispatcher();
    }
    CashBoxApp(){
        // Build the screen.    	
        MainScreen AcctListScreen = new MainScreen();
        pushScreen(AcctListScreen);
    }
}
__________________
Don

Handspring Visor -> Handspring Visor Deluxe -> Palm Treo 650 on VZW -> Palm Treo 700p on VZW -> Blackberry Tour 9360 on VZW
Offline  
Old 10-17-2009, 07:27 PM   #2
Dougsg38p
BlackBerry Extraordinaire
 
Join Date: Mar 2008
Location: Austin, TX
Model: 9700
PIN: N/A
Carrier: T-Mobile
Posts: 1,644
Default

What is the error?
Offline  
Old 10-17-2009, 07:39 PM   #3
doni49
Thumbs Must Hurt
 
Join Date: Aug 2009
Model: Tour
PIN: N/A
Carrier: Verizon
Posts: 84
Default

JVM Error 104Uncaught: Error
__________________
Don

Handspring Visor -> Handspring Visor Deluxe -> Palm Treo 650 on VZW -> Palm Treo 700p on VZW -> Blackberry Tour 9360 on VZW
Offline  
Old 10-17-2009, 07:43 PM   #4
doni49
Thumbs Must Hurt
 
Join Date: Aug 2009
Model: Tour
PIN: N/A
Carrier: Verizon
Posts: 84
Default

The page also shows a "Continue" option and when I click the trackball, the app closes and a dialog pops up that says "Uncaught Excption: java.lang.Error".
__________________
Don

Handspring Visor -> Handspring Visor Deluxe -> Palm Treo 650 on VZW -> Palm Treo 700p on VZW -> Blackberry Tour 9360 on VZW
Offline  
Old 10-17-2009, 08:41 PM   #5
hrbuckley
BlackBerry Extraordinaire
 
Join Date: Jan 2006
Model: LEZ10
OS: 10.0.10
Carrier: Rogers CA
Posts: 1,704
Default

Well, according to the API documentation you should have code similar to this:
Code:
static long idKey = <unique long value that identifes the store>;

static PersistentObject store;
static {
    store = PersistentStore.getPersistentObject( idKey ); 
}
to initialize your PersistentObject.
__________________
My other Blackberry is a PlayBook.
Offline  
Old 10-17-2009, 09:03 PM   #6
doni49
Thumbs Must Hurt
 
Join Date: Aug 2009
Model: Tour
PIN: N/A
Carrier: Verizon
Posts: 84
Default

Thanks. But I still get the same errors.
I changed the code as follows only the changed portion is listed):
Old
Code:
    static Vector Transactions;
    static PersistentObject persistTransactions;
    {
        Transactions = (Vector) persistTransactions.getContents();
        if( Transactions == null ) {
            Transactions = new Vector();
            persistTransactions.setContents( Transactions );
            persistTransactions.commit();
        }
    }
New
Code:
    static long KEY =  0xa3b3159378f59a29L;
    static PersistentObject persistTransactions;
    {
        long KEY =  0xa3b3159378f59a29L;
        persistTransactions = PersistentStore.getPersistentObject( KEY );
        Transactions = (Vector) persistTransactions.getContents();
        if( Transactions == null ) {
            Transactions = new Vector();
            persistTransactions.setContents( Transactions );
            persistTransactions.commit();
        }
    }
Edit: I tried removing the BLUE portion and adding the PURPLE portion--both are shown in the their respective locations. I still get the same errors.
__________________
Don

Handspring Visor -> Handspring Visor Deluxe -> Palm Treo 650 on VZW -> Palm Treo 700p on VZW -> Blackberry Tour 9360 on VZW

Last edited by doni49; 10-17-2009 at 09:08 PM..
Offline  
Old 10-18-2009, 06:01 PM   #7
doni49
Thumbs Must Hurt
 
Join Date: Aug 2009
Model: Tour
PIN: N/A
Carrier: Verizon
Posts: 84
Default

I've continued to try and figure out what's wrong. It seems to be having trouble storing the Category object. As written, I'm creating a Vector of Transactions and then attempting to store the Vector.

When I changed it to a Vector of STRINGS, it gave no errors.

So then I created a new EXTREMELY SIMPLE class and tried persisting a Vector of this new class.

Here's the new class:
Code:
class Test implements Persistable{
	boolean _tst;
	public Test(boolean TST){
		_tst = TST;
	}
}
Here's my new test code. I thought I could persist a Vector of custom objects.

Code:
import java.util.Vector;
import java.lang.String;
import net.rim.device.api.ui.*;
import net.rim.device.api.ui.component.*;
import net.rim.device.api.ui.container.*;
import net.rim.device.api.ui.MenuItem;
import net.rim.device.api.system.*;
import net.rim.device.api.util.Persistable;
import net.rim.device.api.system.PersistentObject;
import net.rim.device.api.system.PersistentStore;

class Test implements Persistable{
	boolean _tst;
	public Test(boolean TST){
		_tst = TST;
	}
}
class CashBoxApp extends UiApplication
{
	static Vector Transactions;
    long KEY =  0xa3b3159378f59a29L;

    static PersistentObject persistTransactions;
    {
        persistTransactions = PersistentStore.getPersistentObject( KEY );
        Transactions = (Vector) persistTransactions.getContents();
        if( Transactions == null ) {
            Transactions = new Vector();
            persistTransactions.setContents( Transactions );
            persistTransactions.commit();
        }
    }
    static void addTransaction(Test a){
        Transactions.addElement(a);
        persistTransactions.commit();
    }
    public static void main(String[] args){
		
	addTransaction(new Test(true));

	CashBoxApp app = new CashBoxApp();
        app.enterEventDispatcher();
    }
    CashBoxApp(){
        // Build the screen.    	
        MainScreen AcctListScreen = new MainScreen();
        pushScreen(AcctListScreen);
    }
}
Edit: My comment about thinking that I could Persist custom objects got me to thinking that I had read something about "Persistable" so I did some checking and added the portion that's in RED above--STILL get teh same errors.
__________________
Don

Handspring Visor -> Handspring Visor Deluxe -> Palm Treo 650 on VZW -> Palm Treo 700p on VZW -> Blackberry Tour 9360 on VZW

Last edited by doni49; 10-18-2009 at 06:16 PM..
Offline  
Old 10-18-2009, 10:30 PM   #8
doni49
Thumbs Must Hurt
 
Join Date: Aug 2009
Model: Tour
PIN: N/A
Carrier: Verizon
Posts: 84
Default

SOLVED! Thanks all for the assistance.

Come to find out it WAS the "implements Persistable" issue--but in an effort to clean eliminate extraneous code (thinking that maybe something in a diff portion of my code was causing this), I got over-zealous and removed too much. Some of what I had removed was causing null pointers.

Now that I've restored my code and added the "implements Persistable" code, it all runs without errors.

My head hurts!
__________________
Don

Handspring Visor -> Handspring Visor Deluxe -> Palm Treo 650 on VZW -> Palm Treo 700p on VZW -> Blackberry Tour 9360 on VZW
Offline  
Closed Thread



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


OEM Battery for MacBook Pro 17

OEM Battery for MacBook Pro 17" A1309 A1297 Early 2009 Mid 2009 2010 MC226

$36.90



A1618 NEW OEM Battery for MacBook Pro 15

A1618 NEW OEM Battery for MacBook Pro 15" Retina A1398 Mid 2015 020-00079

$43.90



NEW OEM Battery A1466 A1369 A1496 A1405 A1377 A1466 for MacBook Air 13 inch picture

NEW OEM Battery A1466 A1369 A1496 A1405 A1377 A1466 for MacBook Air 13 inch

$31.90



NEW OEM A1618 Battery for Apple MacBook Pro 15” Retina 99.5Wh A1398 Mid 2015 picture

NEW OEM A1618 Battery for Apple MacBook Pro 15” Retina 99.5Wh A1398 Mid 2015

$43.90



Genuine A1417 OEM Battery Apple Macbook Pro 15 Retina A1398 Mid 2012 Early 2013 picture

Genuine A1417 OEM Battery Apple Macbook Pro 15 Retina A1398 Mid 2012 Early 2013

$37.90



Genuine OEM A1417 Battery For Apple Macbook Pro 15

Genuine OEM A1417 Battery For Apple Macbook Pro 15" Retina A1398 2012 2013 NEW

$38.90







Copyright 2004-2016 BlackBerryForums.com.
The names RIM and BlackBerry are registered Trademarks of BlackBerry Inc.