If cursor1.getString("Pic") <> "" Then
txtPic.Text = cursor1.getString("Pic")
ImageView1.Bitmap = LoadBitmapSample(File.DirRootExternal, txtPic.Text, 10,110)
End If
If cursor1.getString("Pic") <> Null Then
txtPic.Text = cursor1.getString("Pic")
ImageView1.Bitmap = LoadBitmapSample(File.DirRootExternal & "/DCIM" & "/100Media", txtPic.Text, 10,110)
End If
Are you sure that klaus code didn't work? It should work as the value is not null and not an empty string.
cursor1.getString("Pic") <> ""
Sub LVDb_ItemClick (Position As Int, Value As Object)' click on the entry in the list
Dim idvalue As String
Dim countIt As Int
Dim vBild As String
idvalue = Value
ImageView1.Bitmap = Null
countIt = idvalue.IndexOf("|") 'find location of sperator
idvalue = idvalue.SubString2(0,countIt) 'find first part of label text
ID = idvalue
cursor1 = SQL1.ExecQuery("SELECT * FROM tblUsers where ID = '" & ID & "' ")
For i = 0 To cursor1.RowCount - 1
cursor1.Position = i
txt1.text=cursor1.getString("Username")
txt2.text=cursor1.getString("Password")
txt3.text=cursor1.getString("Desc")
vBild = cursor1.getString("Pic")
If vBild = "" OR vBild = Null Then 'CODE STOPS HERE
vBild = "0.jpg"
Else
vBild = cursor1.getString("Pic")
End If
ImageView1.Bitmap = LoadBitmapSample(File.DirRootExternal & "/DCIM" & "/100Media", vBild, 10,110)
Next
End Sub
Have you traced this code and check what the values indicate? This will give you a better idea of what the variables are being set to leading up to the point that it fails or at the very least generate with debug and get it to tell you the exact line in the Basic4Android code that is throwing the error, it might not be the one you currently suspect.
Sub DBload
LVDb.Clear'need to clear the list
cursor1 = SQL1.ExecQuery("SELECT * FROM tblUsers")
For i = 0 To cursor1.RowCount - 1
cursor1.Position = i
LVDb.AddSingleLine(cursor1.GetString("ID")& "| " &cursor1.GetString("Username"))
LVDb.SingleLineLayout.ItemHeight = 99
LVDb.SingleLineLayout.Label.TextSize = 20
LVDb.SingleLineLayout.Label.TextColor = Colors.Black
LVDb.SingleLineLayout.Label.Color = Colors.White
Next
End Sub
Sub cmdAdd_Click
If txt1.Text = "" Then
Msgbox("You have to enter the name","Missed data field")
Else
'Grab the last ID number which is the highest number
cursor1 = SQL1.ExecQuery("SELECT ID FROM tblUsers")
If cursor1.RowCount > 0 Then
For i = 0 To cursor1.RowCount - 1
cursor1.Position = i
Dim NewID As Int
NewID = cursor1.GetInt("ID")
Next
End If
NewID = NewID +1 ' add 1 to the ID number to make a new ID field
SQL1.ExecNonQuery("INSERT INTO tblUsers VALUES('" & NewID & "','" & txt1.Text & "','" & txt2.Text & "','" & txt3.Text & "','" & txtPic.Text & "')")
DBload
txt1.Text = ""
txt2.Text = ""
txt3.Text = ""
txtPic.Text = ""
txtPOI.RequestFocus
End If
End Sub
Sub LVDb_ItemClick (Position As Int, Value As Object)' click on the entry in the list
Dim idvalue As String
Dim countIt As Int
Dim vBild As String
idvalue = Value
ImageView1.Bitmap = Null
countIt = idvalue.IndexOf("|") 'find location of sperator
idvalue = idvalue.SubString2(0,countIt) 'find first part of label text
ID = idvalue
cursor1 = SQL1.ExecQuery("SELECT * FROM tblUsers where ID = '" & ID & "' ")
For i = 0 To cursor1.RowCount - 1
cursor1.Position = i
txt1.text=cursor1.getString("Username")
txt2.text=cursor1.getString("Password")
txt3.text=cursor1.getString("Desc")
vBild = cursor1.getString("Pic")
If vBild = "" OR vBild = Null Then
vBild = "0.jpg"
Else
vBild = cursor1.getString("Pic")
End If
ImageView1.Bitmap = LoadBitmapSample(File.DirRootExternal & "/DCIM" & "/100Media", vBild, 10,110)
Next
End Sub
Have you tried :
If cursor1.getString("Pic") = "" OR cursor1.getString("Pic") = Null Then
Best regards.
If vBild = "" OR vBild = Null Then
vBild = "0.jpg"
Else
vBild = cursor1.getString("Pic")
EndIf
if cursor1.getString("Pic")="" or cursor1.getString("Pic")=Null then
vBild = "0.jpg"
else
vBild = cursor1.getString("Pic")
end if
LVDb.SingleLineLayout.ItemHeight = 99
LVDb.SingleLineLayout.Label.TextSize = 20
LVDb.SingleLineLayout.Label.TextColor = Colors.Black
LVDb.SingleLineLayout.Label.Color = Colors.White
Isn't the OR bit the issue here.
If you check for it being NULL first, separately and then potentially set it to "" if it is, then execute the code, it should be fine.
I think the issue is when you encounter a NULL and the code attempts to resolve the first part of the If statement, which is NULL and the pointer exception is thrown as it tries to compare it to an empty string at this point.
It may well be better to define the field in SQLite as "" if Null. So then there aren't any NULLs to be handled.
Databases like NULLs but code that retrieves data from DBs almost hates it with a passion.
If cursor1.getString("Pic") = Null OR cursor1.getString("Pic") = "" Then
If vBild = Null OR vBild = "" Then
Incredible, yes, this seems to work!
B4X:If cursor1.getString("Pic") = Null OR cursor1.getString("Pic") = "" Then
Thank you so much for your help, guys!
That is great that you solved. I posted the same answer precisely the same time you were posting. But also, see the rest of my post for additional info.
We use cookies and similar technologies for the following purposes:
Do you accept cookies and these technologies?
We use cookies and similar technologies for the following purposes:
Do you accept cookies and these technologies?