I have code setup that periodically restructures the menu, and other stuff onscreen, after show events and certain other events (like custom ones emitted when you login)
The code is inside a base class that extends Form, and every other form I've made extends it so they al have the same functionality and menu items by default.
FormInitializer()
addShowListener(new ActionListener() { public void actionPerformed(ActionEvent evt) { ... updateEventBar(); updateCommands(); if(addActionBar) BaseActivity.super.addComponent(actionBar); verifyUser(UserManager.getID()); } });
protected final void updateCommands() {
removeAllCommands();
try { Resources images = Resources.open("/images.res"); if (UserManager.isLogged()) { addCommand(new Command("Logout", images.getImage("ic_action_backspace.png"), ID_USER_LOGOUT)); addCommand(new Command("My Profile", images.getImage("ic_action_person.png"), ID_NAVIGATE_HOME)); } addCommand(new Command("Preferences", images.getImage("ic_action_settings.png"), ID_SHOW_PREFERENCES));
addCommand(new Command("Search", images.getImage("ic_action_search.png"), ID_START_SEARCH)); } catch (Throwable t) { Log.e(t); } if (extraCommands == null) { Vector<Command> vectorCommands = additionalCommands(); extraCommands = vectorCommands.toArray(new Command[vectorCommands.size()]); }
for (Command com : extraCommands) { addCommand(com); }And every so often when switching from one form to another, it crashes with the following exception:
E/AndroidRuntime( 9080): java.lang.NullPointerException
E/AndroidRuntime( 9080): at com.codename1.impl.android.CodenameOneActivity.onPrepareOptionsMenu(CodenameOneActivity.java:470)
E/AndroidRuntime( 9080): at android.app.Activity.onPreparePanel(Activity.java:2556)E/AndroidRuntime( 9080): at com.android.internal.policy.impl.PhoneWindow.preparePanel(PhoneWindow.java:464)E/AndroidRuntime( 9080): at com.android.internal.policy.impl.PhoneWindow.doInvalidatePanelMenu(PhoneWindow.java:800)E/AndroidRuntime( 9080): at com.android.internal.policy.impl.PhoneWindow$1.run(PhoneWindow.java:221)E/AndroidRuntime( 9080): at android.view.Choreographer$CallbackRecord.run(Choreographer.java:761)E/AndroidRuntime( 9080): at android.view.Choreographer.doCallbacks(Choreographer.java:574)E/AndroidRuntime( 9080): at android.view.Choreographer.doFrame(Choreographer.java:543)E/AndroidRuntime( 9080): at android.view.Choreographer$FrameDisplayEventReceiver.run(Choreographer.java:747)E/AndroidRuntime( 9080): at android.os.Handler.handleCallback(Handler.java:733)E/AndroidRuntime( 9080): at android.os.Handler.dispatchMessage(Handler.java:95)E/AndroidRuntime( 9080): at android.os.Looper.loop(Looper.java:136)E/AndroidRuntime( 9080): at android.app.ActivityThread.main(ActivityThread.java:5001)E/AndroidRuntime( 9080): at java.lang.reflect.Method.invokeNative(Native Method)E/AndroidRuntime( 9080): at java.lang.reflect.Method.invoke(Method.java:515)E/AndroidRuntime( 9080): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:785)E/AndroidRuntime( 9080): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:601)E/AndroidRuntime( 9080): at dalvik.system.NativeStart.main(Native Method)
Wondering how I can avoid this issue, and if its possible to make small changes, a class here or there, to the codename one source and upload it to the build servers instead of having to do an offline build to change core functionality.
Thanks
addShowListener(new ActionListener() { public void actionPerformed(ActionEvent evt) { Display.getInstance().callSerially(new Runnable() { public void run() { ... updateCommands(); ... } }); } });
private class DrawerItemClickListener implements android.widget.AdapterView.OnItemClickListener {
@Override
public void onItemClick(AdapterView parent, View view, int position, long id) {
if (position >= 10) {
openPopupInfo(position);
} else {
selectItem(position);
}
}
}
private void openPopupInfo(int position) {
switch (position){
case 11:
if (sidebarInfo != null) {
MoneyExchangeDialogFragment dialog = MoneyExchangeDialogFragment.newInstance(sidebarInfo.getCurrency());
dialog.show(getSupportFragmentManager(), "dialog");
Toast.makeText(MainActivity.this, "Open Exchange Popup", Toast.LENGTH_SHORT).show();
}
}
}