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
Possible solutions:
1. Catch this error and ignore it.
2. Add a flag that the list was updated and ignore the event (return immediately).
3. Don't clear the list. Just add new items or update existing items.
Maybe option 1 for a start.
Where do I catch the error and how do I ignore the error?
 
Upvote 0

Declan

Well-Known Member
Licensed User
Longtime User
Great, many thanks - Sorted.
B4X:
    Try
        Dim index As Int= clvEvents.GetItemFromView(Sender)
    Catch
        Return
    End Try
 
Upvote 0
Top