BlackBerry Forums Support Community               

Closed Thread
 
LinkBack Thread Tools
Old 10-17-2009, 08:00 PM   #1 (permalink)
Thumbs Must Hurt
 
Join Date: Aug 2009
Model: Tour
PIN: N/A
Carrier: Verizon
Posts: 84
Post Thanks: 0
Thanked 0 Times in 0 Posts
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, 08:27 PM   #2 (permalink)
BlackBerry Extraordinaire
 
Join Date: Mar 2008
Location: Austin, TX
Model: 9700
PIN: N/A
Carrier: T-Mobile
Posts: 1,644
Post Thanks: 0
Thanked 34 Times in 33 Posts
Default

What is the error?
Offline  
Old 10-17-2009, 08:39 PM   #3 (permalink)
Thumbs Must Hurt
 
Join Date: Aug 2009
Model: Tour
PIN: N/A
Carrier: Verizon
Posts: 84
Post Thanks: 0
Thanked 0 Times in 0 Posts
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, 08:43 PM   #4 (permalink)
Thumbs Must Hurt
 
Join Date: Aug 2009
Model: Tour
PIN: N/A
Carrier: Verizon
Posts: 84
Post Thanks: 0
Thanked 0 Times in 0 Posts
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, 09:41 PM   #5 (permalink)
BlackBerry Extraordinaire
 
Join Date: Jan 2006
Model: LEZ10
OS: 10.0.10
Carrier: Rogers CA
Posts: 1,704
Post Thanks: 20
Thanked 77 Times in 68 Posts
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, 10:03 PM   #6 (permalink)
Thumbs Must Hurt
 
Join Date: Aug 2009
Model: Tour
PIN: N/A
Carrier: Verizon
Posts: 84
Post Thanks: 0
Thanked 0 Times in 0 Posts
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 10:08 PM.
Offline  
Old 10-18-2009, 07:01 PM   #7 (permalink)
Thumbs Must Hurt
 
Join Date: Aug 2009
Model: Tour
PIN: N/A
Carrier: Verizon
Posts: 84
Post Thanks: 0
Thanked 0 Times in 0 Posts
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 07:16 PM.
Offline  
Old 10-18-2009, 11:30 PM   #8 (permalink)
Thumbs Must Hurt
 
Join Date: Aug 2009
Model: Tour
PIN: N/A
Carrier: Verizon
Posts: 84
Post Thanks: 0
Thanked 0 Times in 0 Posts
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


Thread Tools

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

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On





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