*** Update: by adding another variable as XmlLayoutBuilder within Activity_CreateMenu, the program compiles and runs ok.
Solved, sort of.
here was my original post:
This error cropped up while I was using corwin42's handy AppCompat toolbar
It was working fine, then started getting NullPointerException error.
I tried many things, and basically commented out just about everything in Activity_CreateMenu, and started putting things back one at a time.
It was working, and I didn't change any libraries or code for the toolbar. I might have goofed up something else, and even tried going back to the Designer, deleted and re-added the Toolbar.
Just asking if this is an error caused by me, or if you can tell from the log if there is something I can't fix in my own code...
Solved, sort of.
B4X:
Sub Activity_CreateMenu(menu As ACMenu)
' For this sub to work, make sure to include the If Java block for AC CreateOptionsMenu
Log("Activity_CreateMenu")
'ToolBar.InitMenuListener
menu.Clear
Log("adding menu items")
Dim item As ACMenuItem
Log("item as ACMenuItem created")
Dim zz As XmlLayoutBuilder ' <----- HERE IS NEW VARIABLE THAT WORKS
menu.Add2(10,4,"Add Item",zz.GetDrawable("ic_add_white_24dp")).ShowAsAction = item.SHOW_AS_ACTION_ALWAYS
...
here was my original post:
This error cropped up while I was using corwin42's handy AppCompat toolbar
It was working fine, then started getting NullPointerException error.
I tried many things, and basically commented out just about everything in Activity_CreateMenu, and started putting things back one at a time.
It was working, and I didn't change any libraries or code for the toolbar. I might have goofed up something else, and even tried going back to the Designer, deleted and re-added the Toolbar.
Just asking if this is an error caused by me, or if you can tell from the log if there is something I can't fix in my own code...
B4X:
Sub Globals
'These global variables will be redeclared each time the activity is created.
'These variables can only be accessed from this module.
Private AC As AppCompat
Private ToolBar As ACToolBarLight ' type needs to match view in Designer (i.e. ACToolBarDark or ACToolBarLight)
Private content As Panel
Private statusbar As Label
Private ULV As UltimateListView
Private ItemHeight As Int = 60dip
Private cellwidths() As Int
Private res As XmlLayoutBuilder
Dim pf As PreferenceManager
Private xml As XmlLayoutBuilder
Private button1 As Button
Private button2 As Button
Private spinner1 As Spinner
Private butmenu As ACPopupMenu
Private dcolorpicker As ColorPickerDialog
' Keyboard handling
Dim ime As IME
' Database
Dim dbcursor As Cursor
End Sub
Sub Activity_CreateMenu(menu As ACMenu)
' For this sub to work, make sure to include the If Java block for AC CreateOptionsMenu
Log("Activity_CreateMenu")
'ToolBar.InitMenuListener
menu.Clear
Log("adding menu items")
Dim item As ACMenuItem
Log("item as ACMenuItem created")
menu.Add2(10,4,"Add Item",xml.GetDrawable("ic_add_white_24dp")).ShowAsAction = item.SHOW_AS_ACTION_ALWAYS
'menu.Add2(20,3,"Edit List",xml.GetDrawable("ic_mode_edit_white_24dp")).ShowAsAction = item.SHOW_AS_ACTION_ALWAYS
Log("added menu icons")
menu.Add(1,1,"Settings",Null)
menu.Add(2,2,"About",Null)
menu.Add(3,3,"Reset DB",Null)
Log("added menu choices")
Log("adding toolbar")
' Call ToolBar.InitMenuListener and then use the ToolBar_NavigationItemClick event
'ToolBar.InitMenuListener
'ToolBar.Color =AC.GetThemeAttribute("colorPrimary")
'Dim AB As ACActionBar
'AB.Initialize
'AB.ShowUpIndicator = False
'AB.HomeVisible=True
'RefreshToolbarName
End Sub
B4X:
Main resume, found 0 records in ListItems
** Activity (main) Pause, UserClosed = true **
Activity_CreateMenu
adding menu items
item as ACMenuItem created
main_activity_createmenu (java line: 436)
java.lang.NullPointerException: Attempt to read from field 'anywheresoftware.b4a.object.XmlLayoutBuilder b4a.example.main._xml' on a null object reference
at b4a.example.main._activity_createmenu(main.java:436)
at java.lang.reflect.Method.invoke(Native Method)
at anywheresoftware.b4a.BA.raiseEvent2(BA.java:179)
at b4a.example.main._onCreateOptionsMenu(main.java:1032)
at java.lang.reflect.Method.invoke(Native Method)
at anywheresoftware.b4a.BA.runHook(BA.java:152)
at b4a.example.main.onCreateOptionsMenu(main.java:134)
at android.app.Activity.onCreatePanelMenu(Activity.java:3307)
at android.support.v4.app.FragmentActivity.onCreatePanelMenu(FragmentActivity.java:362)
at android.support.v7.view.WindowCallbackWrapper.onCreatePanelMenu(WindowCallbackWrapper.java:98)
at android.support.v7.app.AppCompatDelegateImplBase$AppCompatWindowCallbackBase.onCreatePanelMenu(AppCompatDelegateImplBase.java:335)
at android.support.v7.view.WindowCallbackWrapper.onCreatePanelMenu(WindowCallbackWrapper.java:98)
at android.support.v7.app.ToolbarActionBar.populateOptionsMenu(ToolbarActionBar.java:454)
at android.support.v7.app.ToolbarActionBar$1.run(ToolbarActionBar.java:61)
at android.os.Handler.handleCallback(Handler.java:751)
at android.os.Handler.dispatchMessage(Handler.java:95)
at anywheresoftware.b4a.Msgbox.waitForMessage(Msgbox.java:198)
at anywheresoftware.b4a.Msgbox.msgbox(Msgbox.java:137)
at anywheresoftware.b4a.keywords.Common.Msgbox2(Common.java:440)
at anywheresoftware.b4a.keywords.Common.Msgbox(Common.java:406)
at b4a.example.main._activity_resume(main.java:515)
at java.lang.reflect.Method.invoke(Native Method)
at anywheresoftware.b4a.BA.raiseEvent2(BA.java:179)
at anywheresoftware.b4a.BA.raiseEvent(BA.java:163)
at b4a.example.main.afterFirstLayout(main.java:108)
at b4a.example.main.access$000(main.java:17)
at b4a.example.main$WaitForLayout.run(main.java:80)
at android.os.Handler.handleCallback(Handler.java:751)
at android.os.Handler.dispatchMessage(Handler.java:95)
at android.os.Looper.loop(Looper.java:154)
at android.app.ActivityThread.main(ActivityThread.java:6688)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1468)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1358)
Last edited: