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
New Developer
Posts: 6
Registered: ‎01-04-2009
My Device: Not Specified
Accepted Solution

reference an object using a string value, which is the object's name

is this possible? i want to do something like:

 

String str = "classname"; UiApplication.getUiApplication().pushScreen(str);

thanks Smiley Happy

 

Developer
Posts: 5,339
Registered: ‎09-20-2008
My Device: ***
My Carrier: ***

Re: reference an object using a string value, which is the object's name

No, that is not possible.

 

You can push only the Screen class instance.

Developer
Posts: 5,339
Registered: ‎09-20-2008
My Device: ***
My Carrier: ***

Re: reference an object using a string value, which is the object's name

If you want to use strings as keys use java.util.Hashtable class.

 

Place your objects to the Hashtable and get them back via string unique keys.

 

Like that

 

 

Hashtable myObjects = new Hashtable(); myObjects.put("MyStringKey", myObjectReference); ....... Object myObjectFromTable = myObjects.get("MyStringKey"); if (myObjectFromTable instanceof Screen) { UiApplication.getUiApplication().pushScreen((Screen)myObjectFromTable); }

 

 

 

New Developer
Posts: 6
Registered: ‎01-04-2009
My Device: Not Specified

Re: reference an object using a string value, which is the object's name

nice idea, thanks Smiley Happy

i'm getting this error:

 

cannot find symbol symbol: class Screen UiApplication.getUiApplication().pushScreen((Screen)myObjectFromTable);

 


 

Developer
Posts: 5,339
Registered: ‎09-20-2008
My Device: ***
My Carrier: ***

Re: reference an object using a string value, which is the object's name

You have to add relevant import directive.

 

import net.rim.device.api.ui.Screen;

 

at the start of your java class.

 

I guess you're a novice java developer.

 

In this case check the link below, it will be interesting for you Smiley Happy

 

http://supportforums.blackberry.com/rim/board/message?board.id=java_dev&thread.id=13264

 

New Developer
Posts: 6
Registered: ‎01-04-2009
My Device: Not Specified

Re: reference an object using a string value, which is the object's name

that worked, thanks a lot. thanks for the link Smiley Happy

peace

Highlighted
Developer
Posts: 5,339
Registered: ‎09-20-2008
My Device: ***
My Carrier: ***

Re: reference an object using a string value, which is the object's name

You're welcome Smiley Happy