Hi,
I can't figure out what's wrong with my logic.
I have 2 lists, one with values 1 thru 6 (lstAll), the other with 1,6,3 (lstSelected).
I'm trying to compare the two lists and remove the items that are in lstSelected from lstAll.
I'm not very good at explaining so here's what I have. Any help would be appreciated.
Thanks.
edit: forgot to include error:
I can't figure out what's wrong with my logic.
I have 2 lists, one with values 1 thru 6 (lstAll), the other with 1,6,3 (lstSelected).
I'm trying to compare the two lists and remove the items that are in lstSelected from lstAll.
I'm not very good at explaining so here's what I have. Any help would be appreciated.
Thanks.
B4X:
Sub Globals
Private lstAll,lstSelected As List
End Sub
Sub Activity_Create(FirstTime As Boolean)
lstAll.Initialize
lstSelected.Initialize
For i=1 To 6
lstAll.Add(i)
Next
lstSelected.Add(1)
lstSelected.Add(6)
lstSelected.Add(3)
Log("lstAll= " & lstAll)
Log("lstSelected= " & lstSelected)
compareLists
Sub compareLists
Dim intI,intJ As Int
Dim lstTemp As List
lstTemp.Initialize
lstTemp=lstAll
Log("lstTemp= " & lstTemp)
For i=0 To lstTemp.Size-1
Log("i= " & i & "******")
Log("lstTemp.size= " & lstTemp.Size)
intI=lstTemp.Get(i)
Log("intI= " & intI)
For j=0 To lstSelected.Size-1
intJ=lstSelected.Get(j) ':Log(strJ)
If intI=intJ Then
lstAll.RemoveAt(i)
Log("lstAll= " & lstAll)
Log("lstTemp= " & lstTemp)
Exit
End If
Next
Next
End Sub
edit: forgot to include error:
main_comparelists (java line: 411)
java.lang.IndexOutOfBoundsException: Index: 4, Size: 3
at java.util.ArrayList.get(ArrayList.java:411)
at anywheresoftware.b4a.objects.collections.List.Get(List.java:117)
at b4a.comparelists.main._comparelists(main.java:411)
at b4a.comparelists.main._activity_create(main.java:368)
at java.lang.reflect.Method.invoke(Native Method)
at anywheresoftware.b4a.BA.raiseEvent2(BA.java:191)
at b4a.comparelists.main.afterFirstLayout(main.java:104)
at b4a.comparelists.main.access$000(main.java:17)
at b4a.comparelists.main$WaitForLayout.run(main.java:82)
at android.os.Handler.handleCallback(Handler.java:751)
at android.os.Handler.dispatchMessage(Handler.java:95)
at android.os.Looper.loop(Looper.java:154)
at android.app.ActivityThread.main(ActivityThread.java:6316)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:872)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:762)
java.lang.IndexOutOfBoundsException: Index: 4, Size: 3
at java.util.ArrayList.get(ArrayList.java:411)
at anywheresoftware.b4a.objects.collections.List.Get(List.java:117)
at b4a.comparelists.main._comparelists(main.java:411)
at b4a.comparelists.main._activity_create(main.java:368)
at java.lang.reflect.Method.invoke(Native Method)
at anywheresoftware.b4a.BA.raiseEvent2(BA.java:191)
at b4a.comparelists.main.afterFirstLayout(main.java:104)
at b4a.comparelists.main.access$000(main.java:17)
at b4a.comparelists.main$WaitForLayout.run(main.java:82)
at android.os.Handler.handleCallback(Handler.java:751)
at android.os.Handler.dispatchMessage(Handler.java:95)
at android.os.Looper.loop(Looper.java:154)
at android.app.ActivityThread.main(ActivityThread.java:6316)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:872)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:762)
Last edited: