gpt4 book ai didi

Java Applet - ArrayIndexOutOfBoundsException(第 2 部分)

转载 作者:行者123 更新时间:2023-12-01 16:04:21 27 4
gpt4 key购买 nike

我解决了之前的问题。但是现在在我的图 block map 上...如果我尝试向右移动 9 个图 block ,并尝试到达第 9 个图 block ...我会收到此错误:

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

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

最佳答案

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

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

关于Java Applet - ArrayIndexOutOfBoundsException(第 2 部分),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2945820/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com