java.lang.ArrayIndexOutOfBoundsException: 0 at com.codename1.ui.plaf.UIManager.initFirstTheme(UIManager.java:2156) at com.mycompany.myapp.MyApplication.init(MyApplication.java:33) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) at java.lang.reflect.Method.invoke(Method.java:498) at com.codename1.impl.javase.Executor$4$1.run(Executor.java:308) at com.codename1.ui.Display.processSerialCalls(Display.java:1368) at com.codename1.ui.Display.mainEDTLoop(Display.java:1155) at com.codename1.ui.RunnableWrapper.run(RunnableWrapper.java:120) at com.codename1.impl.CodenameOneThread.run(CodenameOneThread.java:176)
CodePudding user response:
Without seeing the examples of rest of your code I'm limited to the answer I can provide.
I would recommend that you would be best to debug the code and see what contents the array has, and how many times your array is being used in either a loop or check the number it extracts before it tries to get the index element and that it does not exceed the number of contents in the array (Remember they start at 0 not 1).
Example:
// This will throw the same error, "ArrayIndexOutOfBoundsException"
String[] colours = ["red", "blue", "green"];
System.out.println(colours[3]); // This index does not exist, error throws
If you are using a loop (usual culprit because the loop goes one too far), Good alternatives to look into to avoid this error are for-each
Loops! They will not throw this error as they only process the indexes available
String[] colours = ["red", "blue", "green"];
for (String colour : colours) {
System.out.println(colour);
}
If you are using something like .split(String)
to create an array do a check beforehand
String colourList = "red.blue.green"; // 3 elements
String[] colours = colourList.split(".");
if (array.size == 3) {
// there is a 4th element
System.out.println(colours[3]);
} else {
// there is no 4th element
System.out.println(colours[2]);
}