java.lang.RuntimeException: java.lang.NullPointerException

johnaaronrose

Active Member
Licensed User
Longtime User
I have a "java.lang.RuntimeException: java.lang.NullPointerException". From the attached log file, it seems that it might be something to do with Process Globals in the main Activity coding (i.e.happening in the .b4a file) at java line 666 due to the next line in the log being:
at dial2000computing.jewishheritage.main.initializeProcessGlobals(main.java:666)

I have no knowledge of Java. Can anybody tell me how to identify the B4A code line(s) causing the problem?
 

johnaaronrose

Active Member
Licensed User
Longtime User
main Process Globals Code

Can you post the code in Sub Process_Globals?

Below is main Activity Process Globals code. I have a number of other Activities in the app. Please tell me if you also want those fragments:

Sub Process_Globals
'These global variables will be declared once when the application starts.
'These variables can be accessed from all modules.
Private SDDir As String
SDDir = File.DirDefaultExternal & "/"
' SDDir = "/sdcard/"
Private DBFilename
DBFilename = "JewishHeritage.db"
Public SQL1 As SQL
Public Country As String
Country = ""
Public CountryId As Int
Public Centre As String
Centre = ""
Public CentreId As Int
Public Location As String
Location = ""
Public LocationId As Int
Public Aspect As String
Aspect = ""
Public AspectId As Int
Public Latitude, Longitude As String
Public CentreLatitude, CentreLongitude As Float
Public LatitudeList, LongitudeList As List
Public InformationText As String
Public PhotoBitmap As Bitmap
Private btnDownloadEnabled As Boolean
btnDownloadEnabled = False
Private btnOverviewEnabled As Boolean
btnOverviewEnabled = False
Private btnSkipEnabled As Boolean
btnSkipEnabled = False
End Sub

Could this be caused by same InformationHeight variable name being defined in 2 other activities' Process_Globals. even though both specify it as Private?
 
Last edited:
Upvote 0

johnaaronrose

Active Member
Licensed User
Longtime User
Removed offending line

You cannot use File.DirDefaultExternal in Process_Globals. Sub Process_Globals should only be used to declare variables. It is also possible to assign "primitive" values.

The offending line has been in previous versions of app without problem. I've moved the offending line from Process_Globals to Activity_Create in Main: still having problem. Could this be caused by same InformationHeight variable name being defined in 2 other activities' (View & Information) Process_Globals,. even though both specify it as Private?

Log is now:
maininitializeProcessGlobals (java line: 675)

java.lang.RuntimeException: java.lang.NullPointerException

at dial2000computing.jewishheritage.main.initializeProcessGlobals(main.java:675)
at dial2000computing.jewishheritage.main.afterFirstLayout(main.java:80)
at dial2000computing.jewishheritage.main.access$100(main.java:16)
at dial2000computing.jewishheritage.main$WaitForLayout.run(main.java:72)
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:3683)
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:839)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:597)
at dalvik.system.NativeStart.main(Native Method)
Caused by: java.lang.NullPointerException
at dial2000computing.jewishheritage.information._process_globals(information.java:348)
at dial2000computing.jewishheritage.main.initializeProcessGlobals(main.java:671)
... 12 more
 
Upvote 0

johnaaronrose

Active Member
Licensed User
Longtime User
How find B4A line?

No.

Now that you posted the error logs, I see that the error is actually in Sub Process_Globals of the Information module.

Problem was caused by having the line
"InformationHeight = scvInformation.Height" in the Information module's Process_Globals. I've removed it and java error has gone.

How do I find out the problem B4A line when there is a Java exception which does not result in the IDE highlighting it when the debugger is on?
 
Upvote 0

Erel

B4X founder
Staff member
Licensed User
Longtime User
You can see the problematic sub from this line:
Caused by: java.lang.NullPointerException
at dial2000computing.jewishheritage.information._process_globals(information.java:348)
The B4A line doesn't appear because the debugger skips on Process_Globals and Globals (which are special subs).

You can open the java file with a text editor and find the error line. The b4a line will appear in the comment above this line.
 
Upvote 0

johnaaronrose

Active Member
Licensed User
Longtime User
Where is Java file

You can see the problematic sub from this line:

The B4A line doesn't appear because the debugger skips on Process_Globals and Globals (which are special subs).

You can open the java file with a text editor and find the error line. The b4a line will appear in the comment above this line.

Thank you. I found information.java 32 folders below src folder. On opening it I saw each b4a line above its corresponding java line.

However, I'm now having a problem with Activity.LoadLayout("Information") in the Activity_Create sub of the Information module failing at runtime, saying that the Layout file is not found in the Activity_Create of the Information module. This could be due to my changing the name of the Activity & its Layout file from DisplayInformation. Are there places that I should look (e.g. in .java files) to find out the cause of this problem?
 
Upvote 0

johnaaronrose

Active Member
Licensed User
Longtime User
Information Layout file

Did you create a layout file named Information?
You should check the Files tab and see if there is such a layout file.

Yes I did. It's showing in the Files tab. It's in the Files folder as information.bal
 
Upvote 0

johnaaronrose

Active Member
Licensed User
Longtime User
Log

Can you post the error from the logs (note for next time that it is better to start a new thread for a new question)?

Log attached. In 'Global Variables' (at bottom of IDE window) it shows 'Activity BAL(ayout): Layout not available'. In 'Local Variables' (at bottom of IDE window) it shows 'Last Exception java.lang.RuntimeException: Object should first be initialized (ScrollView) and the IDE debugger is pointing to scvInformation.SetLayout(0, 0, 100%x, 100%y) which is the next line of code after Activity.LoadLayout("Information"). scvInformation is a view within the Information layout.

PS I'll remember to start a new thread for a new question next time.

View attachment JHLog.txt
 
Upvote 0
Top