Java Applet - ArrayIndexOutOfBoundsException(第 2 部分)

发布于 2024-09-03 07:09:39 字数 2016 浏览 6 评论 0原文

我解决了之前的问题。但是现在在我的图块地图上...如果我尝试向右移动 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

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

I fixed my previous problem. But now when on my tile map... if I try to go 9 tiles to the RIGHT, and on trying to get to the 9th tile.... I will get this error:

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)

Here is code: http://www.so.pastebin.com/hYkpQf13

I have tried many solutions, all of which have failed.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

2024-09-10 07:09:39

我相信问题是你混淆了坐标。您使用 X 作为左右坐标,使用 Y 作为上下坐标,而实际上应该是相反的方式(或者您应该镜像您的板)。

向右走时,您增加 X,在棋盘上,这意味着您有效地向下移动一行。由于棋盘有 8 行,因此第 9 步棋会让您出界。

I believe the problem is you mix up the coordinates. You use X as the left-right coordinate and Y as the up-down, when it should be the other way around (or you should mirror your board).

Upon going right, you increment X, and on your board, that means effectively you move one row down. Since the board has 8 rows, the 9th move takes you out of bounds.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文