i have an Activity using TABHOST with customlistview, and i load my data from a sqlite table, i keep getting an error message when i try to add data to the customlistview. I have log the data from the SQL table and don't see any NULL value, please help. This is the error i got:
ordermenu_activity_create (java line: 410)
java.lang.NullPointerException: Attempt to read from field 'int android.view.ViewGroup$LayoutParams.width' on a null object reference
at anywheresoftware.b4a.objects.ViewWrapper.getWidth(ViewWrapper.java:140)
at anywheresoftware.b4a.samples.customlistview.customlistview._insertattextitem(customlistview.java:346)
at anywheresoftware.b4a.samples.customlistview.customlistview._addtextitem(customlistview.java:50)
at com.dispatch.dyc.ordermenu._activity_create(ordermenu.java:410)
at java.lang.reflect.Method.invoke(Native Method)
at anywheresoftware.b4a.BA.raiseEvent2(BA.java:179)
at com.dispatch.dyc.ordermenu.afterFirstLayout(ordermenu.java:102)
at com.dispatch.dyc.ordermenu.access$000(ordermenu.java:17)
at com.dispatch.dyc.ordermenu$WaitForLayout.run(ordermenu.java:80)
at android.os.Handler.handleCallback(Handler.java:739)
at android.os.Handler.dispatchMessage(Handler.java:95)
at android.os.Looper.loop(Looper.java:158)
at android.app.ActivityThread.main(ActivityThread.java:7237)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1230)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1120)
This is the code for the Activity:
ordermenu_activity_create (java line: 410)
java.lang.NullPointerException: Attempt to read from field 'int android.view.ViewGroup$LayoutParams.width' on a null object reference
at anywheresoftware.b4a.objects.ViewWrapper.getWidth(ViewWrapper.java:140)
at anywheresoftware.b4a.samples.customlistview.customlistview._insertattextitem(customlistview.java:346)
at anywheresoftware.b4a.samples.customlistview.customlistview._addtextitem(customlistview.java:50)
at com.dispatch.dyc.ordermenu._activity_create(ordermenu.java:410)
at java.lang.reflect.Method.invoke(Native Method)
at anywheresoftware.b4a.BA.raiseEvent2(BA.java:179)
at com.dispatch.dyc.ordermenu.afterFirstLayout(ordermenu.java:102)
at com.dispatch.dyc.ordermenu.access$000(ordermenu.java:17)
at com.dispatch.dyc.ordermenu$WaitForLayout.run(ordermenu.java:80)
at android.os.Handler.handleCallback(Handler.java:739)
at android.os.Handler.dispatchMessage(Handler.java:95)
at android.os.Looper.loop(Looper.java:158)
at android.app.ActivityThread.main(ActivityThread.java:7237)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1230)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1120)
This is the code for the Activity:
B4X:
Sub Activity_Create(FirstTime As Boolean)
'Do not forget to load the layout file created with the visual designer. For example:
'Activity.LoadLayout("Layout1")
Dim i As Int
Dim liststring As String
If FirstTime Then
CurrentTab=1
TabHeight=42
End If
For i=0 To TabCount-1
TabsEnabled(i)=True
TabsVisibility(i)=True
Next
outlist.Initialize(Me,"outlist")
complist.Initialize(Me,"complist")
dispatch_itDir = File.Combine(File.DirDefaultExternal,"/dispatch_it")
SQLdb.Initialize(dispatch_itDir, "dispatchit.db",False)
dbString= "SELECT * from orderstbl WHERE status<>3"
Cursors = SQLdb.ExecQuery(dbString)
For i = 0 To Cursors.RowCount - 1
Cursors.Position = i
liststring = "Order #: " & Cursors.GetString("orderno") & " Pick up Time: " & Cursors.GetString("pickup_time") & CRLF
liststring = liststring & "Customer: " & Cursors.GetString("custname") & CRLF
liststring = liststring & "Address: " & Cursors.GetString("custaddr") & CRLF
liststring = liststring & "Drop off: " & Cursors.GetString("dropaddr") & CRLF
If (Cursors.GetString("comment") <> "") Then
liststring = liststring & "Comment: " & Cursors.GetString("comment") & CRLF
End If
' Log(liststring)
outlist.AddTextItem(liststring,Null)
Log("after add")
Next
Cursors.Close