Troubleshooting guide

38
BlackBerry Java Development Environment Development Guide
DemoAppMenuItem() {
long locationToAddMenuItem =
ApplicationMenuItemRepository.MENUITEM_ADDRESSCARD_VIEW;
addMenuItem(ARG_LAUNCH_CONTACT_DEMO, locationToAddMenuItem, new
ContactsDemoMenuItem());
System.exit(0);
}
private static void addMenuItem(String argOfAppl, long location, ApplicationMenuItem
applMenuItem)
{
ApplicationMenuItemRepository amir = ApplicationMenuItemRepository.getInstance();
ApplicationDescriptor app = ApplicationDescriptor.currentApplicationDescriptor();
//set the argument so that we know which app we want to have launched
app = new ApplicationDescriptor(app, new String[]{ARG_LAUNCH_CONTACT_DEMO});
amir.addMenuItem(location, applMenuItem, app);
}
/**
* Create the menu item classes here
*/
private static class ContactsDemoMenuItem extends ApplicationMenuItem {
ContactsDemoMenuItem() {
super(20);
}
public String toString() {
return “Open the Contacts Demo”;
}
public Object run(Object context) {
BlackBerryContact c = (BlackBerryContact)context; //an error if this doesn’t
work
if ( c != null ) {
Application.getApplication().requestForeground();
//on invokation, will call the main method of this app. with argument as
specified in addMenuItem
} else {
throw new IllegalStateException( “Context is null, expected a Contact
instance”);
}
return null;
}
}
}
Arrange UI components
To arrange components on a screen, use BlackBerry® API layout managers.
The following four classes extend the Manager class to provide predefined layout managers: