Android Question again with initializing issues in B4X

67biscuits

Member
I Dim a list
I initialized a list
I try to .Set a position and get this

Logger connected to: Cat S62 Pro

Error occurred on line: 222 (B4XMainPage)
java.lang.IndexOutOfBoundsException: Index: 0, Size: 0
at java.util.ArrayList.set(ArrayList.java:453)
at anywheresoftware.b4a.objects.collections.List.Set(List.java:123)
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:157)
at anywheresoftware.b4a.objects.EditTextWrapper$1.afterTextChanged(EditTextWrapper.java:83)
at android.widget.TextView.sendAfterTextChanged(TextView.java:10681)
at android.widget.TextView$ChangeWatcher.afterTextChanged(TextView.java:13668)
at android.text.SpannableStringBuilder.sendAfterTextChanged(SpannableStringBuilder.java:1277)
at android.text.SpannableStringBuilder.replace(SpannableStringBuilder.java:577)
at android.text.SpannableStringBuilder.replace(SpannableStringBuilder.java:507)
at android.text.SpannableStringBuilder.replace(SpannableStringBuilder.java:37)
at android.view.inputmethod.BaseInputConnection.replaceText(BaseInputConnection.java:861)
at android.view.inputmethod.BaseInputConnection.commitText(BaseInputConnection.java:197)
at com.android.internal.widget.EditableInputConnection.commitText(EditableInputConnection.java:177)
at com.android.internal.view.IInputConnectionWrapper.executeMessage(IInputConnectionWrapper.java:345)
at com.android.internal.view.IInputConnectionWrapper$MyHandler.handleMessage(IInputConnectionWrapper.java:93)
at android.os.Handler.dispatchMessage(Handler.java:106)
at android.os.Looper.loop(Looper.java:223)
at android.app.ActivityThread.main(ActivityThread.java:7701)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:610)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:952)

lines 217 to 226 Inclusive:

.Set to list:
Private Sub contactText_TextChanged (Old As String, New As String)


    Dim txt As EditText = Sender

    Dim tx As String = txt.text

    Dim t As String = txt.Tag ' set as an int to represent position in list
    
    cntct.set(t, tx)
    
    Log(cntct)

End Sub
 

Erel

B4X founder
Staff member
Licensed User
Longtime User
1. Very bad title.

2. List.Set replaces an existing item. Based on the error message the list is empty (Size: 0) so your attempt to replace an existing item fails.

If you want to start with a list with default values then do something like:
B4X:
Dim z(10) As Int
Dim MyList As List = z
MyList.Set(9, 1)
Note that you can't add or remove items from this list as it is backed by the array.

If you do need to add/remove items:
B4X:
MyList = B4XCollections.CreateList(z)
 
Upvote 0
Top