Android Question dealling with null

afields

Member
Licensed User
hello to all.
i'm using flexible table to show a sql table.
when i click in a row and column i use the value that's in that column for some work.
when that column has a value all's good.
however when that column does not have a value i've got an error message:

Error occurred on line: 841 (Main)
java.lang.NumberFormatException: Invalid double: ""
at java.lang.StringToReal.invalidReal(StringToReal.java:63)
at java.lang.StringToReal.parseDouble(StringToReal.java:248)
at java.lang.Double.parseDouble(Double.java:295)
at anywheresoftware.b4a.debug.RDebugUtils.numberCast(RDebugUtils.java:50)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:515)
at anywheresoftware.b4a.shell.Shell.runMethod(Shell.java:708)
at anywheresoftware.b4a.shell.Shell.raiseEventImpl(Shell.java:337)
....

i had tried to see if the value lenght was = 0 and if so it would return a " " or else a null ...but without sucess
(aparently) the responsable for that error is the
B4X:
Public Sub GetValue(Col As Int, Row As Int) As String
    Dim values() As String
    values = Data.get(Row)
    Return  values(Col)
End Sub

in the tablecustomview v 2.1
how to fix it?
thkx!
 

derez

Expert
Licensed User
Longtime User
Check the value to be not null before you return it, if it is null - return some string that you can handle in the receiving sub.
 
Upvote 0

klaus

Expert
Licensed User
Longtime User
As Erel already said, an empty cell is an empty string.
And you try to convert an empty string to a Double !?
This throws the error. And empty string is not converted to 0.
Before the conversion you need to test if the string is empty.
How do you fill the table and where do the data come from?
 
Upvote 0

afields

Member
Licensed User
hello again!
so :
i have a table in a database that has those fields (sqlite database):
pupil number (int), proc number (int), pupil name (vchar)
i read that table to a flexible table with the same columns ( well another columns exists but does not have problems because are fill with direct value like photo, del, mod, obs)
what i want:
if i "click" in column photo of one row then using a dialog i'll show the pupil photo whose file name is the proc number + " jpg". ( that with no problem!)
however when i "click" in a column photo whose proc number has no value then i have that error that i had told in my first post.
before posting i have tried:
1: to see the proc_number lenght=0 then no photo however i've got an error
2: going directly to table module and in sub get_value ( because it return a string) test if lenght of the value is 0 or null or "null" : i've got an error
3: in sub get_value to return only if that value's lenght is greather than 0 : i've got an error.

so now i'm thinking in concatenate the return's value of get_value with ".jpg" and test if the result is =".jpg" which will indicate that i am in a empty porc number.

(proc number can be empty if does not indicate a pupil but a work group of pupils)
 
Upvote 0

klaus

Expert
Licensed User
Longtime User
Can you post your Table_CellClick event routine?
You should do the test in this routine.
Something like:
B4X:
Private Sub Table_CellClick(col As Int, row As Int)
    Private proc_number As Int
    Private val As String
    val = Table2.GetValue(col, row)
    If col = ProcColIndex Then
        If And val <> "" Then
            proc_number = val
            'your code to show the picture
        End If
    Else
        ' other code
    End If
End Sub
 
Upvote 0

afields

Member
Licensed User
hello again.
now it work as you've told!
here a piece of table event click
B4X:
Sub pupils_CellClick (Col As Int, Row As Int)
    Private selectedrow As Int
    selectedrow = Row
    pupil= tdados.GetValue(0, selectedrow)
    name_al =tdados.GetValue(2,selectedrow)
    Select Col
            Case 4
                Private dr As Int
                Private valor As String
                Private lnproc_al As Int
                valor=tdados.GetValue(1,selectedrow)
                If valor <> "" Then
                    lnproc_al=valor
                Else
                    lnproc_al=-1
                End If
           
                pnlBody.Initialize("")
                pnlBody.LoadLayout("act_fot")
                If lnproc_al<>-1  And File.Exists("/mnt/extsd/Basesexp/fotos",lnproc_al & ".jpg") Then   
                    bitv1.Bitmap=bitv1.LoadScaledBitmap("/mnt/extsd/basesexp/fotos",lnproc_al& ".jpg",bitv1.Width,bitv1.Height,True)
                Else
                    bitv1.Bitmap=bitv1.LoadScaledBitmap("/mnt/extsd/basesexp/fotos","3423.bmp",bitv1.Width,bitv1.Height,True)
                End If
...
thank you klaus
 
Upvote 0
Top