Android Question java.lang.NullPointerException on StdActionBar

MaxWaterfall

Member
Licensed User
Getting this error, I have initialised the variable so I don't know where the error is coming from.

This is the code:

B4X:
bar.Initialize("bar")
  bar.NavigationMode = bar.NAVIGATION_MODE_TABS
  bar.AddTab("Menu")
  bar.AddTab("View")
  bar.AddTab("Send")
Error occurs on second line down.

Error: java.lang.NullPointerException
 

MaxWaterfall

Member
Licensed User
Sorry, this is the full error message:

LogCat connected to: B4A-Bridge: motorola XT1068-353325060764564
--------- beginning of /dev/log/main
** Activity (main) Create, isFirst = true **
** Activity (main) Resume **
** Service (service1) Create **
** Service (service1) Start **
Connected to B4A-Bridge (Wifi)
** Activity (main) Pause, UserClosed = false **
Installing file.
--------- beginning of /dev/log/system
PackageAdded: package:b4a.example
** Activity (main) Create, isFirst = true **
** Activity (main) Resume **
** Activity (main) Pause, UserClosed = true **
** Activity (selectoption) Create, isFirst = true **
** Activity (selectoption) Resume **
** Activity (selectoption) Pause, UserClosed = true **
** Activity (cateringactivity) Create, isFirst = true **
Error occurred on line: 63 (cateringactivity)
java.lang.NullPointerException
at anywheresoftware.b4a.objects.StdActionBar.setNavigationMode(StdActionBar.java:209)
at b4a.example.cateringactivity._activity_create(cateringactivity.java:358)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:515)
at anywheresoftware.b4a.shell.Shell.runMethod(Shell.java:636)
at anywheresoftware.b4a.shell.Shell.raiseEventImpl(Shell.java:305)
at anywheresoftware.b4a.shell.Shell.raiseEvent(Shell.java:238)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:515)
at anywheresoftware.b4a.ShellBA.raiseEvent2(ShellBA.java:121)
at b4a.example.cateringactivity.afterFirstLayout(cateringactivity.java:98)
at b4a.example.cateringactivity.access$100(cateringactivity.java:16)
at b4a.example.cateringactivity$WaitForLayout.run(cateringactivity.java:76)
at android.os.Handler.handleCallback(Handler.java:733)
at android.os.Handler.dispatchMessage(Handler.java:95)
at android.os.Looper.loop(Looper.java:136)
at android.app.ActivityThread.main(ActivityThread.java:5097)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:515)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:785)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:601)
at dalvik.system.NativeStart.main(Native Method)
** Activity (cateringactivity) Resume **
 

MaxWaterfall

Member
Licensed User
Yes I am and no it is not, the app crashes when the program executes this line:
B4X:
bar.NavigationMode = bar.NAVIGATION_MODE_TABS
 

RandomCoder

Well-Known Member
Licensed User
Unbelievably I've had this exact problem last night and kicked myself when I worked out what the problem was :oops:
I my case it was because I set the activity attribute #IncludeTitle to False whilst a splash screen was loaded then intended to load another layout and show the title. Unfortunately I believe that it's not possible to programtically enable and disable the Titlebar and so I now use one activity for the splash screen and another with IncludeTitle set to True for my screen requiring the stdActionBar. Problem now resolved for me at least :D
 

MaxWaterfall

Member
Licensed User
I'm not using the StdActionBar any more but changing the activity attribute #IncludeTitle to True did fix the error!:) Thanks for the help!
 
Top