Java Applet - ArrayIndexOutOfBoundsException(第2页)

时间:2010-05-31 20:24:44

标签: java arrays applet indexoutofboundsexception

我解决了以前的问题。但现在在我的瓷砖地图上...如果我试图将9个瓷砖移到右边,并且试图到达第9个瓷砖......我会得到这个错误:

Exception in thread "AWT-EventQueue-1" java.lang.ArrayIndexOutOfBoundsException: 8
    at tileGen.blocked(tileGen.java:125)
    at tileGen.keyPressed(tileGen.java:58)
    at java.awt.Component.processKeyEvent(Component.java:6221)
    at java.awt.Component.processEvent(Component.java:6040)
    at java.awt.Container.processEvent(Container.java:2041)
    at java.awt.Component.dispatchEventImpl(Component.java:4630)
    at java.awt.Container.dispatchEventImpl(Container.java:2099)
    at java.awt.Component.dispatchEvent(Component.java:4460)
    at java.awt.KeyboardFocusManager.redispatchEvent(KeyboardFocusManager.java:1850)
    at java.awt.DefaultKeyboardFocusManager.dispatchKeyEvent(DefaultKeyboardFocusManager.java:712)
    at java.awt.DefaultKeyboardFocusManager.preDispatchKeyEvent(DefaultKeyboardFocusManager.java:990)
    at java.awt.DefaultKeyboardFocusManager.typeAheadAssertions(DefaultKeyboardFocusManager.java:855)
    at java.awt.DefaultKeyboardFocusManager.dispatchEvent(DefaultKeyboardFocusManager.java:676)
    at java.awt.Component.dispatchEventImpl(Component.java:4502)
    at java.awt.Container.dispatchEventImpl(Container.java:2099)
    at java.awt.Component.dispatchEvent(Component.java:4460)
    at java.awt.EventQueue.dispatchEvent(EventQueue.java:599)
    at java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:269)
    at java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:184)
    at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:174)
    at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:169)
    at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:161)
    at java.awt.EventDispatchThread.run(EventDispatchThread.java:122)

以下是代码:http://www.so.pastebin.com/hYkpQf13

我尝试了很多解决方案,所有解决方案都失败了。

1 个答案:

答案 0 :(得分:1)

我相信问题是你混淆了坐标。你使用X作为左右坐标,使用Y作为 up-down ,当它应该是相反的方式(或者你应该镜像你的电路板)。

在向右移动时,你增加X,并且在你的棋盘上,这意味着你有效地移动了一行向下。由于棋盘有8行,第9步会让你超出范围。