Type ListViewData Null Pointer Exception

rwblinn

Well-Known Member
Licensed User
Longtime User
Hi,

retrieving a string value from a database which has no value results in a null pointer exception.

Code snippet
Sub Globals
Type ListViewDataA (FirstRow As String, SecondRow As String)

Sub lvActivities_Load
Dim Cursor1 As Cursor
...
Dim lvdd As ListViewDataA
lvdd.Initialize
' ---> IF GETSTRING RETURNS NULL THEN JAVA NULL POINTER EXCEPTION WHEN RUNNING
lvdd.FirstRow = Cursor1.GetString("Activity")
lvdd.SecondRow= Cursor1.GetString("ID")
lvActivities.AddTwoLines2(lvdd.FirstRow, lvdd.SecondRow, lvdd)
...

Mitigation by using a string
Dim s As String
lvdd.Initialize
s = Cursor1.GetString("Activity")
If s = Null Then s = ""
lvdd.FirstRow = s
s = Cursor1.GetString("ID")
If s = Null Then s = ""
lvdd.SecondRow= s
lvActivities.AddTwoLines2(lvdd.FirstRow, lvdd.SecondRow, lvdd)
...

Q: Is there an easier way to handle the null pointer exception?

Thank You,
Rob
 

rwblinn

Well-Known Member
Licensed User
Longtime User
Error Log

Hi Erel,

pls find as requested:
java.lang.NullPointerException
at anywheresoftware.b4a.objects.TextViewWrapper.setText(TextViewWrapper.java:38)
at b4a.example.activities._lvactivities_itemclick(activities.java:597)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:507)
at anywheresoftware.b4a.BA.raiseEvent2(BA.java:169)
at anywheresoftware.b4a.BA$2.run(BA.java:272)
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)
java.lang.NullPointerException

Thank You,
Rob
 
Upvote 0
Top