这有什么错误? [英] What kind of error is this?

查看:65
本文介绍了这有什么错误?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

[2/18/17 12:04 PM]:java.lang.ArrayIndexOutOfBoundsException:101

[2/18/17 12:04 PM]:at server.model.shops.ShopAssistant.addShopItem(ShopAssistant.java:637)

[2/18/17 12:04 PM]:at server.model.shops.ShopAssistant.sellItem(ShopAssistant.java) :601)

[2/18/17 12:04 PM]:at server.model.players.packets.BankX2.processPacket(BankX2.java:86)

[2/18/17 12:04 PM]:在server.model.players.PacketHandler.processPacket(PacketHandler.java:137)

[2/18/17 12:04 PM]:at server.model.players.Client.processQueuedPackets(Client.java:1900)

[2/18/17 12:04 PM]:at server.model.players.PlayerHandler.process(PlayerHandler.java) :149)

[2/18/17 12:04 PM]:at server.Server.main(Server.java:186)

[2/18/17 12:04 PM]: java.lang.ArrayIndexOutOfBoundsException: 101
[2/18/17 12:04 PM]: at server.model.shops.ShopAssistant.addShopItem(ShopAssistant.java:637)
[2/18/17 12:04 PM]: at server.model.shops.ShopAssistant.sellItem(ShopAssistant.java:601)
[2/18/17 12:04 PM]: at server.model.players.packets.BankX2.processPacket(BankX2.java:86)
[2/18/17 12:04 PM]: at server.model.players.PacketHandler.processPacket(PacketHandler.java:137)
[2/18/17 12:04 PM]: at server.model.players.Client.processQueuedPackets(Client.java:1900)
[2/18/17 12:04 PM]: at server.model.players.PlayerHandler.process(PlayerHandler.java:149)
[2/18/17 12:04 PM]: at server.Server.main(Server.java:186)






我的尝试:



我是新的我不能告诉你我的尝试。



What I have tried:

im new so i cant tell you what i have tried.

推荐答案

Quote:

ArrayIndexOutOfBoundsException

ArrayIndexOutOfBoundsException



读作超出界限的数组索引

这意味着一个数组大小说10,你试图访问元素12或-2。



使用调试器查看代码中发生的情况。



当你不明白你的代码在做什么或为什么它做它的作用时,答案是调试器

使用调试器,看看你的代码在做什么。只需设置断点并查看代码执行情况,调试器允许您逐行执行第1行并在执行时检查变量,这是一个令人难以置信的学习工具。



调试器 - 维基百科,免费的百科全书 [ ^ ]

http://docs.oracle.com/javase/7/docs/technotes/tools/windows/jdb.html [ ^ ]

https://www.jetbrains.com/idea/help/debugging-your-first-java -application.html [ ^ ]



调试器在这里向您展示您的代码正在做什么,您的任务是与它应该做什么进行比较。

调试器中没有魔法,它没有找到错误,它只是帮助你。当代码没有达到预期的效果时,你就接近了一个bug。


Reads as "Array Index Out Of Bounds Exception"
This means that an array of size "say" 10 and you try to access element 12 or -2.

Use a debugger to see what happen in your code.

When you don't understand what your code is doing or why it does what it does, the answer is debugger.
Use the debugger to see what your code is doing. Just set a breakpoint and see your code performing, the debugger allow you to execute lines 1 by 1 and to inspect variables as it execute, it is an incredible learning tool.

Debugger - Wikipedia, the free encyclopedia[^]
http://docs.oracle.com/javase/7/docs/technotes/tools/windows/jdb.html[^]
https://www.jetbrains.com/idea/help/debugging-your-first-java-application.html[^]

The debugger is here to show you what your code is doing and your task is to compare with what it should do.
There is no magic in the debugger, it don't find bugs, it just help you to. When the code don't do what is expected, you are close to a bug.


为了避免这样的错误,请记住:

1.索引以零;

2.因此,最后一个元素的索引总是小于数组的大小;

3.如果你有一个数组,要获得这个数组的大小,使用
To avoid such a mistake, remember:
1. indexes start with zero;
2. as such the index of the last element is always one less than the size of the array;
3. if you have an array, to get the size of this array, use
array.length

而不是硬编码。

学习 [ ^ ]

instead of a hardcoded number.
Learn [^]


java.lang.ArrayIndexOutOfBoundsException

是由于您要访问大于length的数组索引而导致的数组。



例如:数组长度= 10,数组的最后一个索引= 9 [这是因为索引从0(零)开始],所以如果您正在访问第10个索引,数组索引超出范围的异常将调用。

is caused due to when you are going to access an array index that is greater than length of the array.

eg: array length=10, last index of the array=9 [this is because index are started from 0(zero)], so if you are accessing the 10th index, array index out of bound exception will call.


这篇关于这有什么错误?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆