我的代码中ArrayIndexOutOfBoundsException的原因是什么? [英] What is the reason for ArrayIndexOutOfBoundsException in my code?
本文介绍了我的代码中ArrayIndexOutOfBoundsException的原因是什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在Java中实现凸壳的Graham扫描算法。
I am implementing Graham Scan Algorithm for convex hull in Java.
运行代码时出现此错误。对于输入字符串:10 18
I am getting this error while running the code. For input string: "10 18"
Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException: 0
at Graham.SelectMin(Graham.java:110)
at Graham.GrahamScan(Graham.java:78)
at Graham.main(Graham.java:41)
任何人都可以帮我解决这个错误吗?
Can anyone help me out to solve this error?
谢谢
推荐答案
java.lang.ArrayIndexOutOfBoundsException:0
这意味着您正在尝试访问空数组的元素。 (大小为0的数组。)
This means that you're trying to access an element of an empty array. (An array of size 0.)
您需要具有非负大小的数组才能访问索引0处的元素。
You need to have a non-negative size of the array to be able to access element at index 0.
作为参考,例如,此代码产生相同的错误:
For reference, this code for instance, produces the same error:
int initialSize = 0;
int[] arr = new int[initialSize];
System.out.println(arr[0]);
这篇关于我的代码中ArrayIndexOutOfBoundsException的原因是什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文