开发者

instantiate a MenuItem

I have the following problem with a blackberry demo class:

MenuItem locatorItem = new MenuItem(new StringProvider("Location Search"), 0x230020, 0);
            locatorItem.setCommand(new Com开发者_如何学编程mand(new CommandHandler() 
            (...)

I am using Eclipse and a BlackBerry simulator to get this demo running and I get the 'Cannot instantiate the type MenuItem' error. I don't know why and there's no suggestion to solve it. I imported 'net.rim.device.api.ui.MenuItem;'.


I think you're using the wrong type of MenuItem. net.rim.device.api.ui.MenuItem you are using is specific to the Blackberry.

If this is a J2ME Application/Midlet, just create a javax.microedition.lcdui.Command. They are turned into menu items on the blackberry.

If you're also usingnet.rim.device.api.ui.Screen or any other net.rim classes in the application, this is the way menu items are usually created:

function doSomething() {
   // Your Code Here
}

// In the function building your screen
MenuItem somethingMi = new MenuItem() {
  private MenuItem() { super("Do Something",100001, 5); }

  public void run() { doSomething() };
}

addMenuItem(somethingMI);
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜