List UnsupportedOperationException

warwound

Expert
Licensed User
Longtime User
Is it a bug or not:

B4X:
Sub Process_Globals

End Sub

Sub Globals

End Sub

Sub Activity_Create(FirstTime As Boolean)
   Dim MyList As List
   MyList.Initialize2(Array As Int(1, 20, 14, 9))
   MyList.Clear
End Sub

Sub Activity_Resume

End Sub

Sub Activity_Pause (UserClosed As Boolean)

End Sub

** Activity (main) Create, isFirst = true **
main_activity_create (java line: 233)
java.lang.UnsupportedOperationException
at java.util.AbstractList.remove(AbstractList.java:645)
at java.util.AbstractList$SimpleListIterator.remove(AbstractList.java:77)
at java.util.AbstractList.removeRange(AbstractList.java:665)
at java.util.AbstractList.clear(AbstractList.java:473)
at anywheresoftware.b4a.objects.collections.List.Clear(List.java:68)
at b4a.example.main._activity_create(main.java:233)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:507)
at anywheresoftware.b4a.BA.raiseEvent2(BA.java:165)
at b4a.example.main.afterFirstLayout(main.java:84)
at b4a.example.main.access$100(main.java:16)
at b4a.example.main$WaitForLayout.run(main.java:72)
at android.os.Handler.handleCallback(Handler.java:587)
at android.os.Handler.dispatchMessage(Handler.java:92)
at android.os.Looper.loop(Looper.java:130)
at android.app.ActivityThread.main(ActivityThread.java:3835)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:507)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:858)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616)
at dalvik.system.NativeStart.main(Native Method)
java.lang.UnsupportedOperationException

This has been reported before: http://www.b4x.com/forum/basic4andr...sic4android-v2-00-released-10.html#post111542

And is related to the problem i posted about here: http://www.b4x.com/forum/libraries-...71-passing-b4a-list-arraylist.html#post135851

A List created with the Initialize2 method does not have the same behaviour or type as a list created with the Initialize method.

Martin.
 

warwound

Expert
Licensed User
Longtime User
Ok.

So it's not really a bug as such, more of a limitation that applies to a List created from an Array using Initialize2 method.

Martin.
 

murdoch1976

Member
Licensed User
Longtime User
I'm getting the same error, however for me it's when I use the "RemoveAt" method.

I too have used initialize2 to initialise the control...

lstImages.Initialize2(File.ListFiles(pthRoot & "/" & pthIMG))

... is there any way of removing items from this list without tripping this exception?

java.lang.UnsupportedOperationException
at java.util.AbstractList.remove(AbstractList.java:638)
at anywheresoftware.b4a.objects.collections.List.RemoveAt(List.java:95)
 

murdoch1976

Member
Licensed User
Longtime User
Fixed my own problem.

Did a simple initialize instead of an initialize2, and then performed the "AddAll" method instead to add the items. It no longer crashes when using the RemoveAt method.

Thanks everyone, I mean, me. ;)
 

cbal03

Active Member
Licensed User
Longtime User
I'm having some trouble with a List. I get the same aforementioned error when removing an item.
The list contains 172 items.
List is initialized by:
B4X:
Dim myList As List
myList.Initialize

List is filled by:
B4X:
myList = Regex.Split(Chr(13), myString) 'split up data returned

Value retrieval works ok.
B4X:
filteredResultsCount = myList.Get(0) 'get the count stored in first position

This line generates the error.
B4X:
myList.RemoveAt(0) 'remove the first item from the list

What's does this method require to work correctly?

Thanks
 

cbal03

Active Member
Licensed User
Longtime User
Thank you very much Erel. Works nicely.
Sorry, I didn't consider what Regex.Split is actually doing.
 
Top