【发布时间】:2013-11-19 04:41:11
【问题描述】:
这个错误是什么意思? java.lang.ArrayIndexOutOfBoundsException:-1 ?
java.lang.ArrayIndexOutOfBoundsException: -1
at Game.Game.plantVegetables(Game.java:1160)
at Game.__SHELL11.run(__SHELL11.java:8)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:601)
at bluej.runtime.ExecServer$3.run(ExecServer.java:725)
异常发生在:
Scanner keyIn = new Scanner (System.in);
for(int leftToPlant=10; leftToPlant>0; leftToPlant--)
if (field[row1][column1].equals("t") ||
field[row1][column1].equals("c") ||
field[row1][column1].equals("p") ||
field[row1][column1].equals("r"))
【问题讨论】:
-
您在此处发布的代码将永远无法编译。尝试至少将您的确切代码复制到块级别,但要保持相关性。在这种情况下,你的 for 循环的内容。
标签: java arrays exception indexoutofboundsexception