Quando tento remover uma int
da arrayList
ele simplesmente da erro.
Codigo:
ArrayList<Integer> colors = new ArrayList<>();
colors.add(Color.rgb(119, 103, 141)); colors.add(Color.rgb(33, 10, 208)); colors.add(Color.rgb(203, 100 ,180));
colors.add(Color.rgb(249, 0 ,193)); colors.add(Color.rgb(74, 169, 94)); colors.add(Color.rgb(25, 236, 70));
colors.add(Color.rgb(235, 213, 92)); colors.add(Color.rgb(242, 206, 9)); colors.add(Color.rgb(68, 243, 220));
int teste = colors.get(3);
colors.remove(teste);
Erro:
Process: lordlokon.contarapp, PID: 1840
java.lang.RuntimeException: Unable to start activity ComponentInfo{lordlokon.contarapp/lordlokon.contarapp.MainActivity}: java.lang.ArrayIndexOutOfBoundsException: length=12; index=-458559
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2426)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2490)
at android.app.ActivityThread.-wrap11(ActivityThread.java)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1354)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:148)
at android.app.ActivityThread.main(ActivityThread.java:5443)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:728)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:618)
Caused by: java.lang.ArrayIndexOutOfBoundsException: length=12; index=-458559
at java.util.ArrayList.remove(ArrayList.java:405)
at lordlokon.contarapp.MainActivity.randomizar(MainActivity.java:63)
at lordlokon.contarapp.MainActivity.onCreate(MainActivity.java:52)
at android.app.Activity.performCreate(Activity.java:6245)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1130)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2379)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2490)
at android.app.ActivityThread.-wrap11(ActivityThread.java)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1354)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:148)
at android.app.ActivityThread.main(ActivityThread.java:5443)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:728)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:618)
ArrayList<Color>
ele pede para mudar paraint
0
colors.add()
por linha.