BlackBerry Forums Support Community

BlackBerry Forums Support Community (http://www.blackberryforums.com/)
-   Developer Forum (http://www.blackberryforums.com/developer-forum/)
-   -   Please help - Can't create a menu item! (http://www.blackberryforums.com/developer-forum/258656-please-help-cant-create-menu-item.html)

yahoopitz 03-26-2012 07:13 PM

Please help - Can't create a menu item!
 
*Figured it out

I am a first time developer and have been reading every tutorial and every javadoc I come accross (as well as all forum posts) on how to add a menu item to a native blackberry application, but I can't get it to work.

In this code, I am trying to add a button, "Text", to the menu when you're viewing an email, which will invoke a new SMS. On the line with the *, it returns this error:

Multiple markers at this line
- Syntax error on token ".", { expected
- Syntax error on token "getInstance", Identifier expected after this token

Here is the code:

import net.rim.blackberry.api.invoke.Invoke;
import net.rim.blackberry.api.invoke.MessageArguments;
import net.rim.blackberry.api.mail.Message;
import net.rim.blackberry.api.menuitem.ApplicationMenuIte m;
import net.rim.blackberry.api.menuitem.ApplicationMenuIte mRepository;
import net.rim.device.api.ui.container.MainScreen;

public class Notes extends MainScreen{

MyMenuItem myMenuitem = new MyMenuItem(0);
* ApplicationMenuItemRepository.getInstance().addMen uItem(
ApplicationMenuItemRepository.MENUITEM_EMAIL_VIEW, myMenuitem);
}

class MyMenuItem extends ApplicationMenuItem{
MyMenuItem(int order){
super(order);
}

public Object run(Object context){
Invoke.invokeApplication(Invoke.APP_TYPE_MESSAGES,
new MessageArguments( MessageArguments.ARG_NEW_SMS));

}

public String toString(){
return "TEXT";
}
}
}


What is wrong with this code? Any help would be GREATLY appreciated!

hrbuckley 03-27-2012 07:53 AM

Re: Please help - Can't create a menu item!
 
If you have "figured it out" then post the answer so anyone searching for a similar problem can find an answer instead of frustration.

yahoopitz 03-27-2012 12:43 PM

Re: Please help - Can't create a menu item!
 
Quote:

Originally Posted by hrbuckley (Post 1772893)
If you have "figured it out" then post the answer so anyone searching for a similar problem can find an answer instead of frustration.

I added in a "physical app" to contain this code. So, on the homescreen there is my app to open, which then adds the menu.

However, every time I open the app, it adds ANOTHER button in the menu, instead of adding the button when the app is open, and removing it when it is closed. Any ideas?

hrbuckley 03-27-2012 01:54 PM

Re: Please help - Can't create a menu item!
 
This is an instance where you will need to create a global singleton and only register the menu item when the singleton is created. Have a read through the following link and get back to me if you still have questions:
Sentenced to Life on a Technicality: BlackBerrry Singletons, Application Context and Threads

yahoopitz 03-27-2012 02:20 PM

Re: Please help - Can't create a menu item!
 
Thanks, hrbuckley. What I wound up doing instead was just making the app run on startup and then hiding the Application Icon so that the user would not click it again.

However, i`m not very familiar with RIM`s app policies. Is it alright to do it this way? Essentially, the menu item will not go away unless the app is uninstalled.

hrbuckley 03-27-2012 08:10 PM

Re: Please help - Can't create a menu item!
 
That is a bad idea. You will be wasting resources that way. I think you need to educate yourself a little more on the BlackBerry system or you'll end up writing yourself a pile of problems.


All times are GMT -5. The time now is 06:44 PM.

Powered by vBulletin® Version 3.6.12
Copyright ©2000 - 2014, Jelsoft Enterprises Ltd.