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
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