Android Question IndexOutOfBoundsException

mrumball

Member
Licensed User
Longtime User
I have the following code that throws an IndexOutOfBoundsException and i don't understand why
B4X:
Dim c As Int = 0
        Log(PartToPick)
        Dim test1 As Int = parttopick.Size
        Log("parttopicksize = " & PartToPick.Size)
       
        For  c = 0 To PartToPick.Size -1
        Dim i As String = PartToPick.Get(c)


Error log with the array list items is below
B4X:
(ArrayList) [82-E2MAN-IN_V3.00*1*ODE2 User Manual Invertek , 21-21010-ME*1*Resistor 100R S30814-Q791-A, 29-00002-MO*1*Connector 2 Way 22035025, 29-RESRC-05*1*Relay 1A 5v SPST SRC, 30-FSB20-LV*1*Power Module FSBB20CH60CT, 30-GBJ25-00*1*Rectifier 25A 600V GBJ2506 Rectifier, 31-TXOP2-L10*1*Transformer ODP Size 2 200V 5212 v10.00, 42-E2CL1-75*1*ODE2 S1 LV 0.75/1.5kW Power PCB Assy X1094#13 v13.00, 45-E21TB-00*1*ODE2 Size 1 IP20 Terminal Assembly X1198#1, 45-E2CON-C0*1*ODE2 Control PCB SMT Assy X1098#12 v12.00, 45-E2L1F-75*1*ODE-2 Size 1 200V Filter PCB X1196#3, 50-R71MH-10*1*RFI Choke ODP Size 1 LV v2.02, 60-4TFIG-35*1*Screw M4 x 35 P.TX T20 C/W Ring & Plain 8mm ZY, 60-M3X12-00*3*Screw M3 x 12 P.Tx c/w spring & plain ZC, 60-M3X20-00*1*M3 x 20 PP C/W Spring & Plain ZC PP, 60-M3X20-00*1*M3 x 20 PP C/W Spring & Plain ZC PP, 61-E2S1A-00*1*ODE2 Heatsink Size 1 v2.07 (skimmed), 62-E2F01-BE*1*E2 Front Plastic Size 1 Beijer Grey Assembled, 63-00060-00*1*Fan 60mm Square 12V v1.01, 65-E2SP1-08*1*Spacer Tube 8mm RRSB-4380-8, 65-E2SP1-14*1*Spacer Tube 14mm RRSB-4380-14, 69-DESSI-01*1*Small Dessicant Sachet for Size 1 and 2 Drives, 69-E2BAG-01*1*Bubble Bag Size A, 69-E2TS1-LV*1*E2 S1 200v Thermistrate v1.01, 70-BOXOA-00*1*Carton OD size 1 v1.00]
parttopicksize = 25
codemod1_removeduplicateparts (B4A line: 65)
Dim i As String = PartToPick.Get(c)
java.lang.IndexOutOfBoundsException: Invalid index 24, size is 24
    at java.util.ArrayList.throwIndexOutOfBoundsException(ArrayList.java:251)
    at java.util.ArrayList.get(ArrayList.java:304)
    at anywheresoftware.b4a.objects.collections.List.Get(List.java:117)
    at b4a.example.codemod1._removeduplicateparts(codemod1.java:363)
    at b4a.example.getbomparts._jobdone(getbomparts.java:312)
    at java.lang.reflect.Method.invokeNative(Native Method)
    at java.lang.reflect.Method.invoke(Method.java:511)
    at anywheresoftware.b4a.BA.raiseEvent2(BA.java:170)
    at anywheresoftware.b4a.keywords.Common$5.run(Common.java:958)
    at android.os.Handler.handleCallback(Handler.java:605)
    at android.os.Handler.dispatchMessage(Handler.java:92)
    at android.os.Looper.loop(Looper.java:137)
    at android.app.ActivityThread.main(ActivityThread.java:4424)
    at java.lang.reflect.Method.invokeNative(Native Method)
    at java.lang.reflect.Method.invoke(Method.java:511)
    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:784)
    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:551)
    at dalvik.system.NativeStart.main(Native Method)


any help much appreciated
 

mrumball

Member
Licensed User
Longtime User
I have worked this one out - i was removing items from the list - therefore the list was no longer the size it was at the start
 
Upvote 0
Top