Hi,
I have a text comments field in my sqLite database tables. The contents of the field are optional and so the fields are NULL unless they have at least a string of zero length in them i.e. ""
If you wish to use the search feature of b4xTables and you make the comments field searchable and high-lightable if records have a null in at least one of the searched fields nulls the program crashes in the b4xtable module in the setTextToCell function.
I used an obvious work-around which was to make default the comments fields to "" rather than let sqLite make them nulls, but it would be better if the search function skipped over nulls and ignored them.
I wouldn't say this is a bug just a feature.
Best regards
Rob
I have a text comments field in my sqLite database tables. The contents of the field are optional and so the fields are NULL unless they have at least a string of zero length in them i.e. ""
If you wish to use the search feature of b4xTables and you make the comments field searchable and high-lightable if records have a null in at least one of the searched fields nulls the program crashes in the b4xtable module in the setTextToCell function.
B4xTable Search Error:
** Activity (main) Resume **
Error occurred on line: 506 (B4XTable)
java.lang.NullPointerException: Attempt to invoke virtual method 'java.lang.String java.lang.String.toLowerCase()' on a null object reference
at b4a.gardenBuddyOld.b4xtable._settexttocell(b4xtable.java:3193)
at b4a.gardenBuddyOld.b4xtable$ResumableSub_ImplUpdateDataFromQuery.resume(b4xtable.java:2885)
at anywheresoftware.b4a.shell.DebugResumableSub$DelegatableResumableSub.resumeAsUserSub(DebugResumableSub.java:48)
at java.lang.reflect.Method.invoke(Native Method)
at anywheresoftware.b4a.shell.Shell.runMethod(Shell.java:732)
at anywheresoftware.b4a.shell.Shell.raiseEventImpl(Shell.java:351)
at anywheresoftware.b4a.shell.Shell.raiseEvent(Shell.java:255)
at java.lang.reflect.Method.invoke(Native Method)
at anywheresoftware.b4a.ShellBA.raiseEvent2(ShellBA.java:144)
at anywheresoftware.b4a.BA.raiseEvent(BA.java:193)
at anywheresoftware.b4a.shell.DebugResumableSub$DelegatableResumableSub.resume(DebugResumableSub.java:43)
at anywheresoftware.b4a.keywords.Common$13.run(Common.java:1704)
at android.os.Handler.handleCallback(Handler.java:739)
at android.os.Handler.dispatchMessage(Handler.java:95)
at android.os.Looper.loop(Looper.java:148)
at android.app.ActivityThread.main(ActivityThread.java:5417)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:726)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616)
** Activity (main) Pause, UserClosed = true **
B4xTable Code Where I think It Crashes:
Private Sub SetTextToCell (Text As String, lbl As B4XView, Searchable As Boolean)
If Searchable = False or HighlightSearchResults = False Then
lbl.Text = Text
Else
#if B4J
Dim parent As B4XView = lbl.Parent
If parent.GetView(parent.NumberOfViews - 1).Tag = TextPaneTag Then
parent.GetView(parent.NumberOfViews - 1).RemoveViewFromParent
End If
#End If
If FilterText = "" Then
lbl.Text = Text
Else
Dim x As Int = Text.ToLowerCase.IndexOf(FilterText)
If x = -1 Or (PrefixSearch And x > 0) Then
lbl.Text = Text
Return
End If
#if B4A or B4i
Dim cs As CSBuilder
cs.Initialize.Append(Text.SubString2(0, x)).Color(HighlightTextColor).Append(Text.SubString2(x, x + FilterText.Length)).Pop
cs.Append(Text.SubString(x + FilterText.Length))
#if B4A
lbl.Text = cs
#else if B4i
Dim l As Label = lbl
l.AttributedText = cs
#End If
End If
#Else
TextFlow.Reset
If x > 0 Then
TextFlow.Append(Text.SubString2(0, x)).SetColor(TextColor).SetFont(LabelsFont)
End If
TextFlow.Append(Text.SubString2(x, x + FilterText.Length)).SetColor(HighlightTextColor).SetFont(LabelsFont)
If x + FilterText.Length < Text.Length Then
TextFlow.Append(Text.SubString(x + FilterText.Length)).SetColor(TextColor).SetFont(LabelsFont)
End If
Dim TextPane As B4XView = TextFlow.CreateTextFlow
TextPane.Tag = TextPaneTag
lbl.Text = ""
parent.AddView(TextPane, 0, parent.Height / 2 - 12, parent.Width, parent.Height / 2)
End If
#end if
End If
End Sub
I used an obvious work-around which was to make default the comments fields to "" rather than let sqLite make them nulls, but it would be better if the search function skipped over nulls and ignored them.
I wouldn't say this is a bug just a feature.
Best regards
Rob