我的代码中ArrayIndexOutOfBoundsException的原因是什么?

编程入门 行业动态 更新时间:2024-10-26 12:28:30
本文介绍了我的代码中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的原因是什么?

本文发布于:2023-11-26 03:21:15,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1632428.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:原因   代码   ArrayIndexOutOfBoundsException

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!