java.lang.ArrayIndexOutOfBoundsException 是什么意思? [英] What does java.lang.ArrayIndexOutOfBoundsException mean?

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

问题描述

我是 Java 新手,今天我开始研究数组,但我迷路了.我试图将一些值放入数组中,但出现错误 java.lang.ArrayIndexOutOfBoundsException.

I am new to java and today I started to work on arrays and I'm lost. I am trying to put some values in an array but I'm getting the error java.lang.ArrayIndexOutOfBoundsException.

这是我到目前为止所做的.

Here is what I have done so far.

      int n=6; 
      int[]A= new int [1];

      for(i=0;i<n;i++){
          A[i]=keyboard.nextInt();
      } 

推荐答案

java.lang.ArrayIndexOutOfBoundsException 表示您正在尝试访问不存在的数组索引.

java.lang.ArrayIndexOutOfBoundsException means you are trying to access a array index that doesn't exist.

问题是您的数组大小为 1.但是,您将执行该循环六次.您可以使 n 等于 1,也可以增加数组的大小.

The problem is that your array is of size one.However, you are going through that loop six times. You can either make n equal to one, or increase the size of your array.

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

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