Android Question Crash Report Error - java.lang.NullPointerException

aaronk

Well-Known Member
Licensed User
Longtime User
Hello,

I have got a crash report in my Google Play Developer console..

My guess is it has something to do with the Process_Globals Sub in the my_keypad activity?

B4X:
java.lang.RuntimeException: java.lang.reflect.InvocationTargetException
at my.app.my_keypad.initializeProcessGlobals(my_keypad.java:1313)
at my.app.my_keypad.afterFirstLayout(my_keypad.java:85)
at my.app.my_keypad.access$100(my_keypad.java:16)
at my.app.my_keypad$WaitForLayout.run(my_keypad.java:74)
at android.os.Handler.handleCallback(Handler.java:730)
at android.os.Handler.dispatchMessage(Handler.java:92)
at android.os.Looper.loop(Looper.java:137)
at android.app.ActivityThread.main(ActivityThread.java:5414)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:525)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1187)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1003)
at dalvik.system.NativeStart.main(Native Method)
Caused by: java.lang.reflect.InvocationTargetException
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:525)
at my.app.my_keypad.initializeProcessGlobals(my_keypad.java:1311)
... 12 more
Caused by: java.lang.RuntimeException: java.lang.NullPointerException
at my.app.main.initializeProcessGlobals(main.java:621)
... 15 more
Caused by: java.lang.NullPointerException
at my.app.main._process_globals(main.java:1197)
at my.app.main.initializeProcessGlobals(main.java:593)
... 15 more

After doing some research on this forum I found that Erel said "You cannot use File.DirDefaultExternal in Process_Globals."

My Process_Globals in the my_keypad page looks like below:

B4X:
'Activity module
Sub Process_Globals
    'These global variables will be declared once when the application starts.
    'These variables can be accessed from all modules.
 
    Dim SQL1 As SQL ' Used for getting data from database
    SQL1.Initialize(File.DirDefaultExternal, "database.db", True)
   
    Dim sql_panel_number As String = 1 
   
    Dim runTimer As Timer               
       
    Dim panel_state As String 
 
    Dim connectiontimer As Timer
  
End Sub

I forgot I had File.DirDefaultExternal in Process_Globals.

Just wondering where I should put this in my project so that all Activity's can access it ?

Would I be correct if I leave Dim SQL1 As SQL in Process_Globals but then move SQL1.Initialize(File.DirDefaultExternal, "database.db", True) to the Activity_Create sub ?

Also, Just so I understand, if I put SQL1.initialize... into the Globals sub would I get the same error?
 

aaronk

Well-Known Member
Licensed User
Longtime User
Yes, put the SQL1.Initialize(File.DirDefaultExternal, "database.db", True) in Activity_Create.
Thanks heaps.. I thought that would be correct but just wanted to be 100% before I submitted the update to Google Play.
 
Upvote 0
Cookies are required to use this site. You must accept them to continue using the site. Learn more…