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
wlcolman
Posts: 27
Registered: ‎12-31-2008
My Device: Not Specified
Accepted Solution

menu item's run method not called

Eclipse SDK Version: 3.4.1

BlackBerry JDE Plug-in for Eclipse Version:  1.0.0.50

BlackBerry JDE Component Pack Version:  4.5.0.14

 

I have added a menu item to the contact list. I would like to get the context when the menu item is clicked but the run method is not entered. When the item in the menu is clicked the main routine is entered with correct arguments. Shouldn't the run method get called with the context? No exceptions are thrown.

 

import net.rim.blackberry.api.menuitem.ApplicationMenuItem;
import net.rim.blackberry.api.menuitem.ApplicationMenuItemRepository;
import net.rim.device.api.system.Application;
import net.rim.device.api.system.ApplicationDescriptor;

 

public class BwMain extends Application {
  private static final long APP_ID = 0xf46f5a7867d69ff0L;
  private static final String ARG_LAUNCH_BW = "1";

 

public BwMain() {
    long menuItemLocation = ApplicationMenuItemRepository.MENUITEM_ADDRESSBOOK_LIST;
    ContactsBwMenuItem menuItem = new ContactsBwMenuItem();
    addMenuItem(menuItemLocation, ARG_LAUNCH_BW, menuItem);
    System.exit(0);
  }

 

public static void main(String args[]) {
    if (args == null || args.length == 0) {
      BwMain bwMain = new BwMain();
      bwMain.enterEventDispatcher();
    }
    else {
      System.out.println("App launched from menu");
    }
  }

 

private static void addMenuItem(long location, String argOfAppl,  ApplicationMenuItem appMenuItem) {
    ApplicationMenuItemRepository amir = ApplicationMenuItemRepository.getInstance();
    ApplicationDescriptor app = ApplicationDescriptor.currentApplicationDescriptor();
    app = new ApplicationDescriptor(app, new String[] { ARG_LAUNCH_BW });
    amir.addMenuItem(location, appMenuItem, app);
  }

 

private static class ContactsBwMenuItem extends ApplicationMenuItem {
    ContactsBwMenuItem() {
      super(20);
    }

 

public String toString() {
      return "BW Connection";
    }

 

public Object run(Object context) {
      try {
        System.out.println("Entered run method");
      } catch (Exception e) {
        e.printStackTrace();
      }
      return null;
    }
  }
}

Please use plain text.
Developer
Posts: 432
Registered: ‎02-23-2009
My Device: Not Specified

Re: menu item's run method not called

You can do it like this:

private MenuItem setExitButton = new MenuItem("Exit",1,1){ public void run(){ Dialog.inform("Application is closing."); System.exit(0); } };

 

 


If your problem was get solved then please mark the thread as "Accepted solution" and kudos - your wish

 

 

 

Deepesh Gupta
Please use plain text.
New Developer
wlcolman
Posts: 27
Registered: ‎12-31-2008
My Device: Not Specified

Re: menu item's run method not called

In what way does that help me? I'm looking for a way to get the conext passed by the contact list and the run method associated with the menu item does not get called.
Please use plain text.
Developer
Posts: 432
Registered: ‎02-23-2009
My Device: Not Specified

Re: menu item's run method not called

you can set the value in any variable which you need to pass from contact to run() and now you can use this variable in run()

 

 


If your problem was get solved then please mark the thread as "Accepted solution" and kudos - your wish

 

 

 

Deepesh Gupta
Please use plain text.
New Developer
wlcolman
Posts: 27
Registered: ‎12-31-2008
My Device: Not Specified

Re: menu item's run method not called

The run method is not called so I cannot get the context of the contact. I need the context of the contact selected by the user in order to get information about the contact.
Please use plain text.
Developer
mreed
Posts: 1,041
Registered: ‎07-16-2008
My Device: ಠ_ಠ

Re: menu item's run method not called

[ Edited ]
You are calling System.exit() in the constructor before entering the EventDispatcher. I am guessing that you are adding the menu item, but exiting the application, and so when the menu item is called it doesn't have a reference to the application context anymore and decides not to continue. The menu item will not remove itself when the application exits.
Message Edited by mreed on 02-25-2009 12:56 PM
Please use plain text.