Welcome!

Welcome to the official BlackBerry Support Community Forums.

This is your resource to discuss support topics with your peers, and learn from each other.

inside custom component

Java Development

Reply
Trusted Contributor
Posts: 204
Registered: ‎07-03-2011
My Device: Torch
My Carrier: Digicel

Re: Linking a Table Cell and a display area...Brain Storming

Oh here is the clarified question.

I have a persistable Object with a Vector in it. The Vector is made up of an OBJECT that I created. It actually is a class that extends Object. I used a class because I can't create new methods in an object that I created like this:

Object obj=new Object
{
public void....
};

So I created a class that extends Object. However, because I am using it in a Persistable Object, that class that I created must implement Persistable.

But that is were the real issue comes in. If I make that class Persistable then I am going to have trouble getting the elements from Vector; because I want to assign the information in each element of the Vector to another Object for manipulation. But I get a cast error, because in order to get the data from the array; I must store in it an identical Object, namely the class that I created which extends Object.....Buuut it implements Persistable.

And so I get errors.
_______________________________________________________
Never be close-fisted with the knowledge you've received. For if others were the same to you, you would not be painted as the person you are; the flowing definition of you, would be non existent.

You would be meaningless.
Developer
Posts: 19,636
Registered: ‎07-14-2008
My Device: Not Specified

Re: Linking a Table Cell and a display area...Brain Storming

What you are describing should work, at least how I understand what you are describing. 

 

My persistent Objects usually extend from a Collection class, say Hashtable or Vector.  I can also have a Vector as a private Object in this Persistable Object.  And I can put any Persistable Object into this internal Vector.  And retrieve it later, and cast it back to its original Object.  This seems to be what you are trying to do, and it all works for me. 

 

But remember that all referenced Objects must also be persisted.  So if you persist A, and A has a reference to B, then B will also be persisted (and must be Persistable).

 

Have you been through something like this Video to understand how to use PersistentStore?

http://supportforums.blackberry.com/t5/Java-Development/Storing-persistent-data/ta-p/442747

 

Anyway, if this doesn't help, I suspect I am going to need to see an actual example of the combination of Objects that you are having problems with.  I'm sure someone else would be able to figure out what you are describing, but I can't.  Sorry.

Trusted Contributor
Posts: 204
Registered: ‎07-03-2011
My Device: Torch
My Carrier: Digicel

Re: Linking a Table Cell and a display area...Brain Storming

Are you sure that link was a Video?
_______________________________________________________
Never be close-fisted with the knowledge you've received. For if others were the same to you, you would not be painted as the person you are; the flowing definition of you, would be non existent.

You would be meaningless.
Trusted Contributor
Posts: 204
Registered: ‎07-03-2011
My Device: Torch
My Carrier: Digicel

Re: Linking a Table Cell and a display area...Brain Storming

Here is my Code

 

Persistent Object

public class CellPersistentStorage implements Persistable
{
	Vector information=new Vector();	
	public int HAS_SAVED=0;	
	
	public void createVector(int extent)
	{
		information=new Vector(extent);
		HAS_SAVED=1;
	}
	
	public void addElements(MyObject info,int pos)
	{						
		information.insertElementAt(info, pos);
	}
	
	public String getElementContent(int position,int type)
	{
		MyObject object=new MyObject();
		object=(MyObject) information.elementAt(position);
		String name=object.getName();
		String desc=object.getDescription();
		
		if(type==1)
		{
			return name;
		}
		else
		{
			return desc;
		}
	}		
}

 The Object that I created

public class MyObject extends Object implements Persistable
{
	String eventName;
	String description;
	
	public void setName(String name)
	{
		eventName=name;
	}
	
	public void setDescription(String desc)
	{
		description=desc;
	}
	
	public String getName()
	{
		return eventName;
	}
	public String getDescription()
	{
		return description;
	}
}

 And this is my Screen that uses all of this

public final class FirstScreen extends MainScreen
{
        Cell[] cells;
		
	
	Vector importedData=new Vector(200);
	//***** Persistent Store Stuff
	private static PersistentObject store;
	
	public CellPersistentStorage cellStore=new CellPersistentStorage();
	
	
	public static void inItStore()
	{
		store=PersistentStore.getPersistentObject(0xf55d662373325a9dL);		
	}
	
	public void saveCellData()
	{
		String n;
		String d;
		int createQues=cellStore.HAS_SAVED;
		synchronized(store)
		{	
			if(createQues==0)
			{
				cellStore.HAS_SAVED=1;
				cellStore.createVector(56);
			
				for(int i=0;i<56;i++)
				{
					MyObject obj=new MyObject();
					obj.setName(cells[i].eventN);
					obj.setDescription(cells[i].desc);
					cellStore.addElements(obj, i);
				}
			}
			else
			{
				for(int i=0;i<56;i++)
				{
					MyObject obj=new MyObject();
					obj.setName(cells[i].eventN);
					obj.setDescription(cells[i].desc);
					cellStore.addElements(obj, i);
				}
			}
			store.setContents(cellStore);
			store.commit();
		}
	}	
	public CellPersistentStorage getCellInfo()
	{
		CellPersistentStorage information=new CellPersistentStorage();
		
		synchronized(store)
		{
			information=(CellPersistentStorage)store.getContents();
			if(information==null)
			{
				information=new CellPersistentStorage();
			}
		}
		return information;
	}
	//***********************
	public FirstScreen()
    {        
    	super(NO_VERTICAL_SCROLL|NO_HORIZONTAL_SCROLL);
        setTitle("Table Attempt");
        
        inItStore();       
        cellStore=getCellInfo();     
        
        int total=56;
        cells=new Cell[total];
                     
        
        for(int i=0;i<total;i++)
        {        	     
        	MyObject ob=new MyObject();
        	
        	cells[i]=new Cell("","",9,Field.FIELD_LEFT);
        	CellInputArea.add(cells[i]);
        	cells[i].CELL_ID_NUM=i;

        	ob=(MyObject)cellStore.information.elementAt(i);
        	
        	cells[i].eventN=ob.getName();
        	cells[i].desc=ob.getDescription();  
        	cells[i].setFocusListener(cellFocusSave);
        	
        	String n=cells[i].eventN;
        	cells[i].setText(n);
        }
        
        CellInputBase.add(CellInputArea);
    
        daysAndCellsBase.add(name);
        daysAndCellsBase.add(desc);
        add(daysAndCellsBase);
        add(CellInputBase);
        
        CellInputArea.setFocusListener(cellFocusFind);
    }

	
	public boolean onClose()
	{
		saveCellData();
		System.exit(0);
		return true;
	}

}

 The class Cell is just like a cell that you'd see in excel.

_______________________________________________________
Never be close-fisted with the knowledge you've received. For if others were the same to you, you would not be painted as the person you are; the flowing definition of you, would be non existent.

You would be meaningless.
Trusted Contributor
Posts: 204
Registered: ‎07-03-2011
My Device: Torch
My Carrier: Digicel

Re: Linking a Table Cell and a display area...Brain Storming

When I run it I get this error

 

 

 

 

 

9800-01.png

And then I get this dialog after

9800.png

_______________________________________________________
Never be close-fisted with the knowledge you've received. For if others were the same to you, you would not be painted as the person you are; the flowing definition of you, would be non existent.

You would be meaningless.
Highlighted
Developer
Posts: 19,636
Registered: ‎07-14-2008
My Device: Not Specified

Re: Linking a Table Cell and a display area...Brain Storming

API has this to say about the exception you see:

"This exception is thrown when a thread attempts to access a ControlledAccess object without the appropriate permission"

 

Are you using ControlledAccess to restrict access to the persistent store?  It would appear this is not being done correctly.

 

What statement caused this exception?