Android Question crash when running DBUtils.ExecuteMemoryTable on empty table

Alban

Member
Licensed User
Longtime User
Hi all,

I get the values from a sqlite db table and the following code works fine when said table has at least one record.
B4X:
listRange = DBUtils.ExecuteMemoryTable(SQL1, "SELECT max(value) as max, min(value) as min, avg(value) as average FROM 'track_values' WHERE tracker_id=? ", Array As String(id),0)

But if the table is empty, the app crashes at this point.

I tried things like:
B4X:
Try
        listRange = DBUtils.ExecuteMemoryTable(SQL1, "SELECT max(value) as max, min(value) as min, avg(value) as average FROM 'track_values' WHERE tracker_id=? ", Array As String(id),0)
    Catch
        Log(LastException.Message)
    End Try
    If listRange.IsInitialized Then
        ... do some stuff
        End If

But it doesn't help.

How can I prevent a crash ?

Thanks,

Alban
 

Alban

Member
Licensed User
Longtime User
well the crash happens inside ExecuteMemoryTable it seems.

B4X:
ExecuteMemoryTable: SELECT max(value) as max, min(value) as min, avg(value) as average FROM 'track_values' WHERE tracker_id=?
Error occurred on line: 67 (dbutils)
java.lang.NullPointerException
    at java.lang.StringToReal.parseDouble(StringToReal.java:244)
    at java.lang.Double.parseDouble(Double.java:295)
    at anywheresoftware.b4a.keywords.Common.IsNumber(Common.java:639)
    at java.lang.reflect.Method.invokeNative(Native Method)
    at java.lang.reflect.Method.invoke(Method.java:511)
    at anywheresoftware.b4a.shell.Shell.runMethod(Shell.java:485)
    at anywheresoftware.b4a.shell.Shell.raiseEventImpl(Shell.java:229)
    at anywheresoftware.b4a.shell.Shell.raiseEvent(Shell.java:174)
    at java.lang.reflect.Method.invokeNative(Native Method)
    at java.lang.reflect.Method.invoke(Method.java:511)
    at anywheresoftware.b4a.ShellBA.raiseEvent2(ShellBA.java:93)
    at anywheresoftware.b4a.keywords.Common.CallSub4(Common.java:858)
    at anywheresoftware.b4a.keywords.Common.CallSubNew2(Common.java:815)
    at java.lang.reflect.Method.invokeNative(Native Method)
    at java.lang.reflect.Method.invoke(Method.java:511)
    at anywheresoftware.b4a.shell.Shell.runMethod(Shell.java:485)
 
Upvote 0

Alban

Member
Licensed User
Longtime User
Hi Erel,

Thanks for the answer, but I get the same crash. The crash log I posted before indicates it happens inside dbutils, so when it is actually running ExecuteMemoryTable, not in a case after listRange has been populated or not.
As soon as I add a value that matches the criteria (tracker_id = xxx) then the code works fine.

Or maybe sqlite doesn't support doing min/max/averages on empty values ?
Alban
 
Upvote 0

Alban

Member
Licensed User
Longtime User
OK I see, apparently listRange is not null, however it contains null values. So the "If listRange <> Null Then" test doesn't work, and the program crashes when I try "If (IsNumber(row(0))) Then".
Thanks ! I'll add a if row(0) <> Null test.
 

Attachments

  • b4a crash.png
    b4a crash.png
    41.9 KB · Views: 172
Upvote 0
Top