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)

- 3,585
- 2
- 7
- 38

- 13
- 3
-
1https://stackoverflow.com/questions/5554734/what-causes-a-java-lang-arrayindexoutofboundsexception-and-how-do-i-prevent-it – fantaghirocco Mar 15 '22 at 15:38
-
You are trying to access an element of an array outside of what is inside the array, in this case, because the 1st (0th) element is not present I would suggest your array is not initialised. We cant help you more without some sample code to see what you are trying to do. – JohnnyJP Mar 17 '22 at 10:25
2 Answers
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]);
}

- 103
- 2
- 13
-
this is my code : public void start() { if(current != null){ current.show(); return; } UIBuilder uib = new UIBuilder(); UIBuilder.registerCustomComponent("OnOffSwitch", OnOffSwitch.class); Form home = (Form) uib.createContainer(theme, "Formulaire"); home.show(); } – linda ammar Mar 15 '22 at 18:23
Your theme file is missing or broken. I guess you created it via an old method. I suggest using https://start.codenameone.com/ to create a maven project which is the preferred way to create Codename One applications. Notice it no longer requires the plugins.

- 51,749
- 5
- 35
- 65