ClassCastException in MenuItem
IM saving a MenuItem in an attribute of an object.
When later I call the run method, I get a ClassCastException.
Any solution?
Thank you.
Its a TextField$ TogglingMenuItem.
Its very strange, but I was doing controller.getSureType () .run ();<-- this="">-->
But if I do suretype MenuItem = controller.getSureType (); SureType.Run)<-- this="">-->
Weird, no?
Thank you!
Tags: BlackBerry Developers
Similar Questions
-
Hello...
I would like to add the image icon to a MenuItem, but I do not know how...
I do not have any code.Please help me... if anyone has code or advice please share...
Unfortunately not possible with the right WebWorks, you must write a custom extension to do it for you. More details on this here http://supportforums.blackberry.com/t5/Web-and-WebWorks-Development/Building-a-BlackBerry-WebWorks-J...
(a list of the currently available API community: https://github.com/blackberry/WebWorks-Community-APIs/tree/master/Smartphone)
-
This was annoys me but didn't really think to post so far, in the 1.3 version of the SDK, MenuItem (String, int, int) is marked as obsolete, but there is no other manufacturer for it, then why is it marked obsolete without another manufacturer? So basically in the "Problems" section, I have 'Problems' on all THE MenuItems as warnings for being obsolete, but I've got NO solution for it because there is no other visible manufacturer?
In addition, in the "javadoc" for MenuItem, that's what it shows
[QUOTE]
net.rim.device.api.ui.MenuItem
Represents an abstract menu item.
Each element has an ordinal by specifying the sort order in the menu. A separator is automatically inserted between adjacent elements whose ordinals differ at least 0x00010000. Each item has a priority by specifying that one should be the default value. A lower value indicates a higher priority.
Creating items menu with commands
Since BlackBerry 6.0 API, you can use command framework API to create a menu item. The procedure is the following:
- Set the features to make using a CommandHandler. The order manager can be limited to your application, or can be registered is available to any application on the BlackBerry smartphone.
- On your screen, optionally specify the context of the menu item by calling setCommandContext(). The context may be required to determine what should be the command handler.
- Associate the menu item to a command by calling setCommand(). The command defines what to run when the menu item is selected by acting as a proxy to an instance of a class that extends a command handler. The command is executed only if there is no implementation of practicable. If the context is specified, it is passed to the command executes the method. Otherwise, this menu item is passed.
Code example
class MyUiScreen extends MainScreen { public MyUiScreen() { //... // Create MenuItem with command context MenuItem myItem = new MenuItem("My Menu Item", 110, 10); myItem.setCommandContext(new Object() { public String toString() { return "My MenuItem Object"; } }); // Set command to be invoked by the MenuItem myItem.setCommand(new Command(new DialogCommandHandler())); addMenuItem(myItem); } // A CommandHandler implementation which will be executed unconditionally class DialogCommandHandler extends CommandHandler { public void execute(ReadOnlyCommandMetadata metadata, Object context) { Dialog.alert("Executing command for " + context.toString()); } }
Creating menu items by subclassing and by implementing Runnable
If subclassing the extension class must implement the Runnable interface that supports in turn Expedition summary of actions from the menu during activation.
... // setup the menu items MenuItem item = new MyMenuItem(); menu.addItem(item); ... class MyMenuItem extends MenuItem { MyMenuItem() { super(MyResourceBundle.getBundle(), MyResource.MY_MENU_ITEM, 0, 100); } public void run() { // do something } }
[/ QUOTE]
StringProvider: "Provides a string that can be changed. The most common use would be for locale changes. "If you hard-code the channels then it is useless, if you use a resource bundle then it is great because you simply provide the family resource and ID to the creation and the rest is handled internally.
-
Highlight / selected MenuItem
Hello
When the user pressed a MenuItem, is it possible to highlight the selected item when the user click the menu of the phone again? Y at - there any sample code I can read on this?
Thank you in advance.
Kind regards
Joshua.
You can do if you change the order of Menu after clicking on Menu2 get this order:
Menu2
Menu1
Menu3because the first item in the menu will be selected by default
-
Add MenuItem to the mapping of Blackberry, only when it is called from my application
Hi all
I develop a Blackberry application that calls the Blackberry plan using the api to Invoke.
I need to add the menu item to this map of blackberry only when it is called from my application (means, blackberry card should not have any other newly added menuItem when it is called directly as a standalone application).
Is this possible? If so, how is it possibe?
Help, please.
I guess you can try:
1. Add the menu item
2 call
3. remove the menu call back form element
-
Within a single class what steps should I take to implement a selection MenuItem "get"?
I have a single class that extends screen that contains a single menu that contains MenuItems:
- New
- Edit
- View
- Output
For the New, Edit and display screens, I just want to use a class that extends the screen.
When one of these MenuItems are selected, I need to be:
- Get an identifier for the class that extends the screen, looking at the method MenuItem.getId ().
- Pass a parameter of the run() method in MenuItem to the class that extends the screen.
The goal of each is well just to get a unique identifier that tells the screen to get the various parameters to change the layout of the screen and repaint.
What is a good design implemented or the best implementation which is recommended?
Thank you
passing the parameter or by calling a setter on the screen are very good.
-
ApplicationMenuItemRepository:removeMenuItem does not delete added proviously MenuItem
Hello
I use following code for in my MIDlet startup() adds a MenuITem to BlackBerry menu
////////////////////////////////////////////////////////////////////// net.rim.blackberry.api.menuitem.ApplicationMenuItemRepository repository = net.rim.blackberry.api.menuitem.ApplicationMenuItemRepository.getInstance(); GlobalMenuItem smi = new GlobalMenuItem(); //to remove previously added Item - But it always returns false boolean b = repository.removeMenuItem(ApplicationMenuItemRepository.MENUITEM_SYSTEM, smi); repository.addMenuItem(ApplicationMenuItemRepository.MENUITEM_SYSTEM, smi); //////////////////////////////////////////////////////////////////////
But each time you launch the app I see keep seal the MenuITem in the BlackBerry HomeScreen menu. removeMenuItem doesn't seem to work? Whats wron?
He would remove the menu correctly - item but the menu item is not yet added.
to remove the previous menu item you would need a reference to it.
I suggest using the runtimestore or an Autostart entry point.
-
ClassCastException on Manager.createPlayer problem with DataSource
I run the code BufferedPlayback (JDE 4.7.0) example loading a local file (LimitedRateStreamingSource to the source of data):
final LimitedRateStreamingSource source = new LimitedRateStreamingSource("file:///store/home/user/test/test.wav"); source.setContentType("audio/x-wav"); final Player player = Manager.createPlayer(source);
but when I create the player a ClassCastException is thrown.
Search with google I found this method performs a cast to CommonDataSource, and this leads to the exception (http://discussion.forum.nokia.com/forum/showthread.php?t=113902).I can't figure out how to solve this problem... someone has any advice?
LimitedRateStreamingSource in this example expects a HTTP URL. When you use it with a file:/// URL a FileConnection is returned by the Connector.open call, which triggers a ClassCastException.
You will need to modify the example to use a FileConnection instead of a ContentConnection.
-
JVM error 104 Eception: ClassCastException
Hi all
When I run an application on the Simulator, between start-up Simulator displays an error like below...
JVM error 104
Eception: ClassCastException
Why it is so?
Thank you and best regards.
Hi Peter,.
Sorry for the late reply. I just saw your message and tried to run my application after you have cleaned the Simulator. It worked fine for the moment. Actually seeing the (especially this line ReliableTransmissionHelper.
stack trace (ReliableTransmissionListener, String, TransmissionService) line: 105 ), I could not think that cleaning the simulator could be the solution...Thank you very much.
-
Hello
I m developing an application printing email and I want to put a menu item in the emails with the option 'print with... '. ». I use this:
PrintByMenuItem myMenuitem = new PrintByMenuItem (0);
ApplicationMenuItemRepository.getInstance (.addMenuItem (ApplicationMenuItemRepository.MENUITEM_EMAIL_VIEW),
myMenuitem, ApplicationDescriptor.currentApplicationDescriptor ());
ApplicationMenuItemRepository.getInstance (.addMenuItem (ApplicationMenuItemRepository.MENUITEM_EMAIL_EDIT),
myMenuitem, ApplicationDescriptor.currentApplicationDescriptor ());
ApplicationMenuItemRepository.getInstance (.addMenuItem)
ApplicationMenuItemRepository.MENUITEM_MESSAGE_LIST, myMenuitem, ApplicationDescriptor.currentApplicationDescriptor ());My application has two versions, with ads or no ads. When the user to install the first version and then they want to install the second version, the application will overwrite and will be only one application in the device.
The problem is that when I install the second version, the menu item 'print with... '. ' appears twice. How can I do to if a menu item exist in enamel, doesn´t repeat the menuItem?
I ve tried using removeMenuItem before adding the menu item with:
ApplicationMenuItemRepository.getInstance (.removeMenuItem)
ApplicationMenuItemRepository.MENUITEM_EMAIL_VIEW, myMenuitem);
ApplicationMenuItemRepository.getInstance (.removeMenuItem)
ApplicationMenuItemRepository.MENUITEM_EMAIL_EDIT, myMenuitem);
ApplicationMenuItemRepository.getInstance (.removeMenuItem)
ApplicationMenuItemRepository.MENUITEM_MESSAGE_LIST, myMenuitem);But doesn´t works.
Thank you.
This is not how it would work production / the device. After restarting the device, the menu item will be deleted from the repository, and you will have a menu item.
However, if you leave your app and try again (if you save the menu items at the application startup) the you'll thus duplication. If this isn't the case, then you should not worry.
If this is the case, then I suggest your store a veriable TERM as a check to ensure no duplicates.
-
MenuItem - NoClassDefFound error
Hello
I am trying to add a MenuItem to my project:
protected void makeMenu (menu Menu, for example int) {}
super.makeMenu (menu, for example);
menu. Add (new MyMenuItem());
}
class MyMenuItem extends MenuItem {}
{MyMenuItem()}
Super (new StringProvider ('menu option text'), 100000, 0);
}
}
but when I click on the Menu button I get NoClassDefFound
Thank you
5.0.0 has a MenuItem constructor that takes a StringProvider. Which was introduced only 6.0.0. That means you're probably compile to 6.0.0 and running on 5.0.0 what you shouldn't do.
-
What is a good implementation of creation from records in a database SQLite MenuItems?
From my understanding and reading of the API MenuItem KB, I need to extend the class MenuItem for each menu item that I want to create.
... // setup the menu items MenuItem item = new MyMenuItem(); menu.addItem(item); ... class MyMenuItem extends MenuItem { MyMenuItem() { super(MyResourceBundle.getBundle(), MyResource.MY_MENU_ITEM, 0, 100); } public void run() { // do something } }
I returned a list of five to eight records to a SQLite database, and I want to as the label of each record (String) to be a label for the menu item.
Do I just loop through the records and create a MenuItem for each record and add the menu item to the menu in the loop?
{for(each record)}
create MenuItem
Add MenuItem to the menu
}
Or is he a good implementation for this?
Thank you
Slight variation:
class MyMenuItem extends MenuItem {}
MyMenuItem (String menuLabel) {}
Super (menuLabel, 0, 100);
}
public void run() {}
do something
}
}{for(each record)}
excerpt from label
create MenuItem (label)
Add MenuItem to the menu
}
-
ObjectChoiceField and ChoiceField$ ChangeOptionChoiceField classcastexception
one line in fieldchangelistener of my ObjectChoiceField, I have this line:
choice final int = (field) .getSelectedIndex ((ObjectChoiceField));
but he gives this exception:
ClassCastException: Cannot mount net.rim.device.api.ui.component.ChoiceField$ ChangeOptionChoiceField (id = 91958272) at net.rim.device.api.ui.component.ObjectChoiceField
How can I me index newly selected of the ObjectChoiceField in the Interior of the listener?
I tried to use a final ObjectChoiceField so I could access it just inside the listener, but it I still get the value of previous for the selected index.
my code:
final distance ObjectChoiceField = new ObjectChoiceField ("Menu choose:", menu list);
If (menuList.length > 1) {}
Dialog.Alert ("length =" + menuList.Length);
Flash = Integer.ToString (menu list [Dialog.ask ("which menu?", menuList, 0 "")] .getValue ());
Dialog.Alert ("Flash =" + Flash);
distance.setChangeListener (new FieldChangeListener () {}
' Public Sub fieldChanged (field field, int context) {}
choice final int = (field) .getSelectedIndex ((ObjectChoiceField));
Dialog.Alert ("get next choice");
final int choice = distance.getSelectedIndex ();
Dialog.Alert ("location =" + choices);
Field.Get
final int ctx = context;
New Thread() {}
public void run() {}
loadMenus (ctx, choice);
}
}. start();
}
});objectSymbol = new ObjectChoiceField ("", ARRAY, 0, Field.FIELD_LEFT)
{
protected void fieldChangeNotify (int context)
{
indexCurrency = getSelectedIndex();
}
}; -
How to dynamically change text to a MenuItem
What I'm trying to do is
either place a "tick" in front of the menuitem tag
or
Change the text.
I tried more to mount the getTextStringProvider by
protected void makeMenu(Menu menu, int instance) { MenuItem item = new MenuItem(new StringProvider("App"), 0, 0){ public StringProvider getTextStringProvider() { return menuDisco ? new StringProvider("Stop Job") : new StringProvider("Start Job"); } };
but it did not work...
I don't see how you can change the menu when the application is already running, or even place a tick to say he is running and not running.
Don't change within brand change outside MenuItem when the MenuItem created and pass the StringProvider function of the State.
-
MenuItem, duplication on ApplicationMenuItemRepository
Hi guys!
I'm creating an application is adds a MenuItem to the menu system.
This means that it will be visible in all applicactions.
Everything works fine, but there is a small problem.
When you enter the application (via the application in the bb menu icon), a configuration screen will appear.
Everything is fine, except that MenuItem creates and adds to the Menu system, once again... and if you close and open the configuration screen, it happens again... and so on...
I tried to use the AddMenu as a thread as a background application, but it continues to be.
Here is my sample code...
any ideas?
Main application class:
public class MyApp extends UiApplication{ private BackgroundClass bgThread; public static void main(String[] args){ MyApptheApp = new MyApp(); theApp.enterEventDispatcher(); } public MyApp() { bgThread = new BackgroundClass(); bgThread.start(); pushScreen(new ConfigScreen()); } protected void onExit() { bgThread.stop(); } }
Thread class:
public class BackgroundClass extends Thread { MenuItem myMenuItem = new MenuItem(0); public void run() { ApplicationMenuItemRepository.getInstance().addMenuItem(ApplicationMenuItemRepository.MENUITEM_SYSTEM,myMenuItem); } public synchronized void stop() { ApplicationMenuItemRepository.getInstance().removeMenuItem(ApplicationMenuItemRepository.MENUITEM_SYSTEM,myMenuItem); } }
The ConfigScreen class has nothing about it, so it is useless to post...
Any ideas?
Thanks in advance!
See you soon!
RuntimeStore store = RuntimeStore.getRuntimeStore(); String msg = "item1"; long ID = 0x60ac754bc0867248L; Object obj = store.get(ID); if(obj == null) { MenuItemClass menuItem = new kMenuItemClass(0,this); ApplicationMenuItemRepository repository = ApplicationMenuItemRepository.getInstance(); long id = ApplicationMenuItemRepository.MENUITEM_PHONE; repository.addMenuItem(id, menuItem); try { store.put( ID, msg ); } catch(IllegalArgumentException e) { } }
Maybe you are looking for
-
I am trying to impliment a rule to count the number of files in a directory, and if the number of files exceeds 10 000 it will sound an alarm and send an email to the administration team. Someone at - it a rule created similar to what I can change? O
-
CTI Route Point Call Forwarding
Hi all I'm running 10.5 CM and wanted to know if it was possible before/road called of a Point of ITC road to another CTI Route Point AND at the same time fighter pilot. We have just received a new switchboard console and it does not support the Poin
-
What is the difference between restricted and unrestricted PIX?
Please give me information on the above topic.
-
I'm looking for a program that will help me with my logo and place it on the product I designed that I have a patent for. The logo has 2 letters this overlap and then I need the complete words of the logo at the back of the product. Anyone have any s
-
purchase of a new Summit of office
I have a pavilion A520n which is outdated is obsolete can get I'm absolutely not a computer giant, but after looking at the website of hp I looked and read some reviews on the 500z hp pavilion elite apparently there everything what I might use it as