Android Question List.Clear crush

yaniv hanya

Active Member
Licensed User
I have this code

B4X:
If currentFilesLst.Size>0 Then
        currentFilesLst.Clear
    End If
currentFilesLst is alist of files names and has data. when it gets to the currentFilesLst.Clear
it crush and i get this log

Error occurred on line: 112 (Main)
java.lang.UnsupportedOperationException
at java.util.AbstractList.remove(AbstractList.java:161)
at java.util.AbstractList$Itr.remove(AbstractList.java:374)
at java.util.AbstractList.removeRange(AbstractList.java:571)
at java.util.AbstractList.clear(AbstractList.java:234)
at anywheresoftware.b4a.objects.collections.List.Clear(List.java:69)
at java.lang.reflect.Method.invoke(Native Method)
at anywheresoftware.b4a.shell.Shell.runVoidMethod(Shell.java:777)
at anywheresoftware.b4a.shell.Shell.raiseEventImpl(Shell.java:354)
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.raiseEvent2(BA.java:180)
at anywheresoftware.b4a.debug.Debug.delegate(Debug.java:262)
at b4a.example.main._fillmainlist(main.java:566)
at b4a.example.main._finedview(main.java:1199)
at b4a.example.main._img3_click(main.java:1467)
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.raiseEvent2(BA.java:180)
at anywheresoftware.b4a.BA.raiseEvent(BA.java:176)
at anywheresoftware.b4a.objects.ViewWrapper$1.onClick(ViewWrapper.java:80)
at android.view.View.performClick(View.java:5675)
at android.view.View$PerformClick.run(View.java:22641)
at android.os.Handler.handleCallback(Handler.java:836)
at android.os.Handler.dispatchMessage(Handler.java:103)
at android.os.Looper.loop(Looper.java:203)
at android.app.ActivityThread.main(ActivityThread.java:6251)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1063)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:924)
it worked before and i cann't understend what hapend
what should i chck?
 

emexes

Well-Known Member
Licensed User
To diagnose the problem, try:
B4X:
Do While CurrentFilesLst.Size > 0
    Log( CurrentFilesList.Get(0) )
    CurrentFilesList.RemoveAt(0)
Loop
... and if that works (wtf?) then perhaps just delete the Log line and it's: job done!

One possibility is that you've added the list to itself (I'm pretty sure recursion is allowed) and when that particular item is deleted, it... well, I don't know what would happen, but I'm sure there would be some complaining about it aka error message!!!

:)
 
Last edited:

Erel

Administrator
Staff member
Licensed User
In the sake of completeness, lists that are based on arrays are also read-only:
B4X:
Dim MyList As List = Array(1, 2, 3, 4)
MyList.Add(5) 'crash!
Dim MyList2 As List
MyList2.Initialize
MyList2.AddAll(Array(1, 2, 3, 4))
MyList2.Add(5) 'does not crash
 
Top