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)
uj5u.com熱心網友回復:
在沒有看到其余代碼示例的情況下,我僅限于我可以提供的答案。
我建議您最好除錯代碼并查看陣列有哪些內容,以及您的陣列在回圈中使用了多少次,或者在嘗試獲取索引元素之前檢查它提取的數字,并且它不超過陣列中的內容數(記住它們從 0 開始而不是 1)。
例子:
// This will throw the same error, "ArrayIndexOutOfBoundsException"
String[] colours = ["red", "blue", "green"];
System.out.println(colours[3]); // This index does not exist, error throws
如果您使用的是回圈(通常是罪魁禍首,因為回圈走得太遠),避免此錯誤的好方法是for-each回圈!他們不會拋出這個錯誤,因為他們只處理可用的索引
String[] colours = ["red", "blue", "green"];
for (String colour : colours) {
System.out.println(colour);
}
如果您使用類似.split(String)創建陣列的方法,請事先進行檢查
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]);
}
轉載請註明出處,本文鏈接:https://www.uj5u.com/yidong/444350.html
