Hmm, seems to be that onCreateOptionsMenu is called before Activity_Create. I can't reproduce it here since the oldest Android Version I can test on is 2.3.7 and there I can't see this problem.
Try to change the call to SetCheckboxState in Activity_CreateMenu to an CallSubDelayed() call. This should fix the problem.
Corwin, thanks for replay.
I did it, i made the change, but i new error is generated.
I did this in the CreateMenu:
Sub Activity_CreateMenu(Menu As ACMenu)
Menu.Clear
Dim item As ACMenuItem
Menu.Add2(10, 1, "Plus one", xml.GetDrawable("ic_plus_one_black_24dp")).ShowAsAction = item.SHOW_AS_ACTION_IF_ROOM
Menu.Add2(20, 2, "Refresh", xml.GetDrawable("ic_refresh_black_24dp")).ShowAsAction = item.SHOW_AS_ACTION_ALWAYS
Menu.Add(1, 3, "Overflow1", Null)
Menu.Add(2, 4, "Overflow2", Null)
Menu.Add(3, 5, "Overflow3", Null)
'Sync Checkboxes with the Menu
'SetCheckBoxState(Menu)
CallSubDelayed(Menu,"SetCheckBoxState")
End Sub
And this the new error.
LogCat connected to: B4A-Bridge: samsung GT-P1000N
--------- beginning of /dev/log/main
** Activity (main) Pause, UserClosed = false **
** Activity (main) Create, isFirst = false **
** Activity (main) Resume **
** Activity (main) Pause, UserClosed = false **
** Activity (main) Create, isFirst = false **
** Activity (main) Resume **
** Activity (main) Pause, UserClosed = false **
** Activity (main) Create, isFirst = false **
** Activity (main) Resume **
--------- beginning of /dev/log/system
** Activity (main) Pause, UserClosed = false **
** Activity (main) Create, isFirst = false **
** Activity (main) Resume **
hasIcon: false
hasIcon: false
hasIcon: false
hasIcon: false
hasIcon: false
hasIcon: false
** Activity (main) Pause, UserClosed = true **
** Service (starter) Destroy **
Copying updated assets files (1)
** Service (starter) Create **
** Service (starter) Start **
** Activity (main) Create, isFirst = true **
** Activity (main) Resume **
** Activity (main) Pause, UserClosed = true **
** Service (starter) Destroy **
Installing file.
PackageAdded: package:com.tmcappstore.ce
** Service (starter) Create **
** Service (starter) Start **
** Activity (main) Create, isFirst = true **
** Activity (main) Resume **
** Activity (main) Pause, UserClosed = true **
** Service (starter) Destroy **
Copying updated assets files (1)
** Service (starter) Create **
** Service (starter) Start **
** Activity (main) Create, isFirst = true **
** Activity (main) Resume **
** Activity (main) Pause, UserClosed = true **
** Service (starter) Destroy **
Streams_terminated
sending message to waiting queue (CallSubDelayed - UpdateStatus)
Connected to B4A-Bridge (Wifi)
sending message to waiting queue (CallSubDelayed - UpdateStatus)
Installing file.
PackageAdded: package:de.amberhome.appcompat.toolbarmenuexample
Copying updated assets files (2)
** Activity (main) Create, isFirst = true **
Error occurred on line: 54 (Main)
java.lang.RuntimeException: java.lang.NullPointerException
at anywheresoftware.b4a.keywords.LayoutBuilder.loadLayout(LayoutBuilder.java:166)
at anywheresoftware.b4a.objects.PanelWrapper.LoadLayout(PanelWrapper.java:134)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:507)
at anywheresoftware.b4a.shell.Shell.runMethod(Shell.java:703)
at anywheresoftware.b4a.shell.Shell.raiseEventImpl(Shell.java:340)
at anywheresoftware.b4a.shell.Shell.raiseEvent(Shell.java:247)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:507)
at anywheresoftware.b4a.ShellBA.raiseEvent2(ShellBA.java:134)
at de.amberhome.appcompat.toolbarmenuexample.main.afterFirstLayout(main.java:102)
at de.amberhome.appcompat.toolbarmenuexample.main.access$000(main.java:17)
at de.amberhome.appcompat.toolbarmenuexample.main$WaitForLayout.run(main.java:80)
at android.os.Handler.handleCallback(Handler.java:587)
at android.os.Handler.dispatchMessage(Handler.java:92)
at android.os.Looper.loop(Looper.java:123)
at android.app.ActivityThread.main(ActivityThread.java:3687)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:507)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:842)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:600)
at dalvik.system.NativeStart.main(Native Method)
Caused by: java.lang.NullPointerException
at de.amberhome.objects.appcompat.ACCheckBoxWrapper.DesignerCreateView(ACCheckBoxWrapper.java:61)
at anywheresoftware.b4a.objects.CustomViewWrapper.AfterDesignerScript(CustomViewWrapper.java:70)
at anywheresoftware.b4a.keywords.LayoutBuilder.loadLayout(LayoutBuilder.java:158)
... 21 more
** Activity (main) Resume **