Android Question Error CustomListView

Declan

Well-Known Member
Licensed User
Longtime User
I receive the following intermittent error:
Error occurred on line: 216 (CustomListView)
java.lang.RuntimeException: Object should first be initialized (JavaObject).

Error is Here:
B4X:
Public Sub GetItemFromView(v As View) As Int
    Dim parent = v, current As Object
    Do While (parent Is Panel) = False Or sv.Panel <> parent
        current = parent
        Dim jo As JavaObject = current
        parent = jo.RunMethod("getParent", Null)
    Loop
    v = current
    Return v.Tag
End Sub

Called from Here:
B4X:
Sub txtEvents_FocusChanged (HasFocus As Boolean)
        Dim index As Int= clvEvents.GetItemFromView(Sender)
        Dim pnl As Panel = clvEvents.GetPanel(index)
        Dim caltext As EditText = pnl.GetView(2)
        Dim caltime As Label = pnl.GetView(0)

    If HasFocus=True  Then
        MyCalTime = caltime.text
        MyCalBody = caltext.text

        LogColor("Cal Date: " & MyCalDate, Colors.blue)
        LogColor("Cal Time: " & MyCalTime, Colors.blue)
        LogColor("Cal Body: " & MyCalBody, Colors.blue)
      
        If MyCalBody <> "" Then
' Do some stuff
        End If
    End If
End Sub

The full Error Log:
B4X:
Error occurred on line: 216 (CustomListView)
java.lang.RuntimeException: Object should first be initialized (JavaObject).
    at anywheresoftware.b4a.AbsObjectWrapper.getObject(AbsObjectWrapper.java:50)
    at anywheresoftware.b4j.object.JavaObject.getCurrentClass(JavaObject.java:258)
    at anywheresoftware.b4j.object.JavaObject.RunMethod(JavaObject.java:118)
    at java.lang.reflect.Method.invoke(Native Method)
    at java.lang.reflect.Method.invoke(Method.java:372)
    at anywheresoftware.b4a.shell.Shell.runMethod(Shell.java:708)
    at anywheresoftware.b4a.shell.Shell.raiseEventImpl(Shell.java:337)
    at anywheresoftware.b4a.shell.Shell.raiseEvent(Shell.java:247)
    at java.lang.reflect.Method.invoke(Native Method)
    at java.lang.reflect.Method.invoke(Method.java:372)
    at anywheresoftware.b4a.ShellBA.raiseEvent2(ShellBA.java:134)
    at anywheresoftware.b4a.BA$1.run(BA.java:293)
    at android.os.Handler.handleCallback(Handler.java:815)
    at android.os.Handler.dispatchMessage(Handler.java:104)
    at android.os.Looper.loop(Looper.java:194)
    at android.app.ActivityThread.main(ActivityThread.java:5631)
    at java.lang.reflect.Method.invoke(Native Method)
    at java.lang.reflect.Method.invoke(Method.java:372)
    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:959)
    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:754)

Another Error from Logs:
B4X:
Copying updated assets files (1)
** Service (starter) Create **
** Service (starter) Start **
** Activity (main) Create, isFirst = true **
** Activity (main) Resume **
Selected date: 31/12/2016
Selected date: 01/12/2016
Error occurred on line: 216 (CustomListView)
java.lang.RuntimeException: Object should first be initialized (JavaObject).
    at anywheresoftware.b4a.AbsObjectWrapper.getObject(AbsObjectWrapper.java:50)
    at anywheresoftware.b4j.object.JavaObject.getCurrentClass(JavaObject.java:258)
    at anywheresoftware.b4j.object.JavaObject.RunMethod(JavaObject.java:118)
    at b4a.example.customlistview._getitemfromview(customlistview.java:136)
    at b4a.example.main._txtevents_focuschanged(main.java:1138)
    at java.lang.reflect.Method.invoke(Native Method)
    at java.lang.reflect.Method.invoke(Method.java:372)
    at anywheresoftware.b4a.shell.Shell.runMethod(Shell.java:708)
    at anywheresoftware.b4a.shell.Shell.raiseEventImpl(Shell.java:340)
    at anywheresoftware.b4a.shell.Shell.raiseEvent(Shell.java:247)
    at java.lang.reflect.Method.invoke(Native Method)
    at java.lang.reflect.Method.invoke(Method.java:372)
    at anywheresoftware.b4a.ShellBA.raiseEvent2(ShellBA.java:134)
    at anywheresoftware.b4a.BA$1.run(BA.java:293)
    at android.os.Handler.handleCallback(Handler.java:815)
    at android.os.Handler.dispatchMessage(Handler.java:104)
    at android.os.Looper.loop(Looper.java:194)
    at android.app.ActivityThread.main(ActivityThread.java:5631)
    at java.lang.reflect.Method.invoke(Native Method)
    at java.lang.reflect.Method.invoke(Method.java:372)
    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:959)
    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:754)
** Activity (main) Pause, UserClosed = true **
 
Last edited:

Declan

Well-Known Member
Licensed User
Longtime User
Version of CLV I am using: version: 1.20
Log as requested:
B4X:
Log Sender: android.widget.EditText{dac4daa VFED..CL ......ID 120,10-1190,60 #1bf}

Complete Error Log:
"Selected date: 01/12/2016" comes from AnotherDatePicker.
B4X:
** Service (starter) Create **
** Service (starter) Start **
** Activity (main) Create, isFirst = true **
** Activity (main) Resume **
Log Sender: android.widget.EditText{dac4daa VFED..CL .F...... 120,10-1190,60 #1bf}
Selected date: 01/12/2016
Log Sender: android.widget.EditText{dac4daa VFED..CL ......ID 120,10-1190,60 #1bf}
Error occurred on line: 216 (CustomListView)
java.lang.RuntimeException: Object should first be initialized (JavaObject).
    at anywheresoftware.b4a.AbsObjectWrapper.getObject(AbsObjectWrapper.java:50)
    at anywheresoftware.b4j.object.JavaObject.getCurrentClass(JavaObject.java:258)
    at anywheresoftware.b4j.object.JavaObject.RunMethod(JavaObject.java:118)
    at java.lang.reflect.Method.invoke(Native Method)
    at java.lang.reflect.Method.invoke(Method.java:372)
    at anywheresoftware.b4a.shell.Shell.runMethod(Shell.java:708)
    at anywheresoftware.b4a.shell.Shell.raiseEventImpl(Shell.java:337)
    at anywheresoftware.b4a.shell.Shell.raiseEvent(Shell.java:247)
    at java.lang.reflect.Method.invoke(Native Method)
    at java.lang.reflect.Method.invoke(Method.java:372)
    at anywheresoftware.b4a.ShellBA.raiseEvent2(ShellBA.java:134)
    at anywheresoftware.b4a.BA$1.run(BA.java:293)
    at android.os.Handler.handleCallback(Handler.java:815)
    at android.os.Handler.dispatchMessage(Handler.java:104)
    at android.os.Looper.loop(Looper.java:194)
    at android.app.ActivityThread.main(ActivityThread.java:5631)
    at java.lang.reflect.Method.invoke(Native Method)
    at java.lang.reflect.Method.invoke(Method.java:372)
    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:959)
    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:754)
 
Upvote 0

Declan

Well-Known Member
Licensed User
Longtime User
The EditText (txtEvents) is in the Layout (CIEvents) which is called by the CustomListView (CalendarCLV).
I have attached the project ZIP.
Requires a small SQLite DB:
B4X:
    Dim m As Map
    m.Initialize 'clear the map
    m.Put("id", DBUtils.DB_TEXT)
    m.Put("caltype", DBUtils.DB_TEXT)
    m.Put("caltime", DBUtils.DB_TEXT)
    m.Put("caldate", DBUtils.DB_TEXT)
    m.Put("calbody", DBUtils.DB_TEXT)
    DBUtils.CreateTable(Starter.SQL0, "calendar", m, "")
 

Attachments

  • ProjectZIP.zip
    44.3 KB · Views: 180
Upvote 0

Declan

Well-Known Member
Licensed User
Longtime User
Attached is the project with database. Only 1 line of data is inserted into the table.
Additional data can be inserted by click on EditText in CLV of "Events:.
Exception is thrown after changing CLVs (Buttons: Classes / Homework / Events / Sports)
AND
a new date is selected from the AnotherDatePicker (Shown by click on Image)
 

Attachments

  • ProjectZIP.zip
    44.6 KB · Views: 179
Upvote 0

Declan

Well-Known Member
Licensed User
Longtime User
No joy.
I have rewritten the project using TabStripViewPager and still error.
Eish, driving me crazy.....
 

Attachments

  • ProjectZIP.zip
    51.8 KB · Views: 166
Upvote 0

Declan

Well-Known Member
Licensed User
Longtime User
Thanks for your assistance.
V6.50 is AWESOME.
I have attached the Latest project files.
Steps to reproduce the error:
Open app, it will default on today's date.
1) Click on Tab "My Events & Activities".
2) Click on List.
3) Add new entry - (Click "Done" on keyboard)
4) Open ADP (Click on Logo)
5) Select another date - say: 1/12/2016
6) Msgbox "Got new Date"
7) Click OK
8) ERROR

I am using a MediaTek 10.1" Rooted tablet
Android 5.1

Error Log:
B4X:
** Service (starter) Create **
** Service (starter) Start **
** Activity (main) Create, isFirst = true **
Day of Week: Tuesday
** Activity (main) Resume **
Log Sender: android.widget.EditText{36028a32 VFED..CL .F.P.... 128,0-1280,55 #fd}
Cal Time:  4:00 am
Cal Body:
Cal Date: 13/12/2016
Cal Time: 4:00 am
Cal Body: kjhgf
InsertMaps (first query out of 1): INSERT INTO [calendar] ([caltype], [caltime], [caldate], [calbody]) VALUES (?, ?, ?, ?)
Current Date 13/12/2016
New Date 01/12/2016
Log Sender: android.widget.EditText{36028a32 VFED..CL ......ID 128,0-1280,55 #fd}
Error occurred on line: 216 (CustomListView)
java.lang.RuntimeException: Object should first be initialized (JavaObject).
    at anywheresoftware.b4a.AbsObjectWrapper.getObject(AbsObjectWrapper.java:50)
    at anywheresoftware.b4j.object.JavaObject.getCurrentClass(JavaObject.java:258)
    at anywheresoftware.b4j.object.JavaObject.RunMethod(JavaObject.java:118)
    at b4a.example.customlistview._getitemfromview(customlistview.java:76)
    at b4a.example.main._txtcievents_focuschanged(main.java:2462)
    at java.lang.reflect.Method.invoke(Native Method)
    at java.lang.reflect.Method.invoke(Method.java:372)
    at anywheresoftware.b4a.shell.Shell.runMethod(Shell.java:708)
    at anywheresoftware.b4a.shell.Shell.raiseEventImpl(Shell.java:340)
    at anywheresoftware.b4a.shell.Shell.raiseEvent(Shell.java:247)
    at java.lang.reflect.Method.invoke(Native Method)
    at java.lang.reflect.Method.invoke(Method.java:372)
    at anywheresoftware.b4a.ShellBA.raiseEvent2(ShellBA.java:134)
    at anywheresoftware.b4a.BA$1.run(BA.java:293)
    at android.os.Handler.handleCallback(Handler.java:815)
    at android.os.Handler.dispatchMessage(Handler.java:104)
    at android.os.Looper.loop(Looper.java:194)
    at android.app.ActivityThread.main(ActivityThread.java:5631)
    at java.lang.reflect.Method.invoke(Native Method)
    at java.lang.reflect.Method.invoke(Method.java:372)
    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:959)
    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:754)
 

Attachments

  • ProjectZIP.zip
    52.1 KB · Views: 181
Upvote 0

Erel

B4X founder
Staff member
Licensed User
Longtime User
The problem is here:
B4X:
Sub GetEvents(SelectedDate As String)
   DateTime.DateFormat = "dd/MM/yyyy"
   MyCalDate = SelectedDate
   clvEvents.clear '<----------------

You are removing the old views and creating new ones.
This call fails as the view no longer belongs to the CLV:
B4X:
Dim index As Int= clvEvents.GetItemFromView(Sender)
 
Upvote 0

Declan

Well-Known Member
Licensed User
Longtime User
Thanks, that is awesome.
However, if I do not clear the CLV, additional items are appended to the list every time "GetEvent" is called?
How would I clear the CLV?
 
Upvote 0

eps

Expert
Licensed User
Longtime User
I think maybe there is a not missing from Erel's post.. e.g. You are removing the old views and not creating new ones.

?
 
Upvote 0
Top