0 0

请教这个 java.lang.ArrayIndexOutOfBoundsException: 0 异常5

代码如下:
package test;

public class Test {

	public static void main(String[] args) {

		final int num2 = Integer.parseInt(args[0]);

	}

}

编译时,会报
Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException: 0
at test.Test.main(Test.java:7)

请教大虾

问题补充:其实各位回答的都不错,可是我只能选一个,确实不是编译时出错,是运行时报的错。

我有点思维定式了,我以为在用args参数的时候会在运行时等待输入!!

⊙﹏⊙b汗~
2010年1月27日 09:47

4个答案 按时间排序 按投票排序

0 0

采纳的答案

引用
编译时,会报
Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException: 0
at test.Test.main(Test.java:7)




首先说明:我在JDK1.6中编译时没问题的。

其次: 从你的堆栈可以看出,这是在运行时报的错。

最终的结论是: 运行时忘了加命令时参数了

应该这样运行:java  test.Test  参数




2010年1月27日 10:45
0 0

这个args是在java Test 命令后面加的

必须提供了args才能够取的 否则为一个空的字符串数组

如果在Eclipse中的话请在(Open Run Dialog)代开的对话框中
对Test类运行的 Arguments参数填值  用空格隔开

2010年1月27日 10:39
0 0

哥,你挺厉害的,你的输入参数啊,你用了主方法的参数,运行的时候是需要输入参数的。

2010年1月27日 10:33
0 0

呵呵,那肯定要报这错误的。因为你还未输入数据,所以args数组中还没值,你现在取它的第一值,那肯定是数组越界异常。
先判断:if(args.length!=0)

2010年1月27日 10:32

相关推荐

    java.lang.ArrayIndexOutOfBoundsException: 0 split转义字符问题

    (本人的博客愧对语文老师->又臭又长哈哈...java.lang.ArrayIndexOutOfBoundsException: 0 纳尼??? 好吧我把问题用一段简单的代码展示出来(只为复现问题) 我直接取System.out.println(strings[0]);代码片 原创文章

    AXMLPrinter2.jar解决ArrayIndexOutOfBoundsException问题

    AXMLPrinter2.jar解决ArrayIndexOutOfBoundsException问题,绝对有效

    AXMLPrinter2修改版 解决java.lang.ArrayIndexOutOfBoundsException 加批处理bat

    1、将xml文件放入layout中,点击start.bat即可编译成相应的txt文件。 2、亲测绝对好用。

    java 数组下标越界异常(ArrayIndexOutOfBoundsException)

    java 数组下标越界异常(ArrayIndexOutOfBoundsException) java 数组下标越界异常(ArrayIndexOutOfBoundsException)

    GIF图 java.lang.ArrayIndexOutOfBoundsException

    GIF图 java.lang.ArrayIndexOutOfBoundsException . 网上有一个是jdk1.7适用的。这个是改成1.6之后的。

    java 异常总结

    java.lang.ArrayIndexOutOfBoundsException 数组索引越界异常。当对数组的索引值为负数或大于等于数组大小时抛出。 java.lang.ArrayStoreException 数组存储异常。当向数组中存放非数组声明类型对象时抛出。 java....

    cdh-hive2.1.1版本orc格式表读取包数组越界替换包

    Caused by: java.lang.ArrayIndexOutOfBoundsException: 7 at org.apache.orc.OrcFile$WriterVersion.from(OrcFile.java:145) at org.apache.orc.impl.OrcTail.getWriterVersion(OrcTail.java:74) at org.apache....

    Android APK 加密 解密工具

    Android APK 加密 解密工具 使用这个工具加密后 别人打开你的APK需要输入密码

    APK XML解析及反编译

    java.lang.ArrayIndexOutOfBoundsException: 128 at android.content.res.StringBlock.getShort(StringBlock.java:231) at android.content.res.StringBlock.getString(StringBlock.java:91) at android.content....

    AXMLPrinter2.jar 反编译XML文件

    java.lang.ArrayIndexOutOfBoundsException: 82 at android.content.res.StringBlock.getShort(StringBlock.java:231) a t android.content.res.StringBlock.getString(StringBlock.java:91) at android.content....

    AXMLPrinter2

    java.lang.ArrayIndexOutOfBoundsException: 128 at android.content.res.StringBlock.getShort(StringBlock.java:231) at android.content.res.StringBlock.getString( StringBlock.java:91) at android.content...

    AXMLPrinter2错误修正版本

    java.lang.ArrayIndexOutOfBoundsException: 128 at android.content.res.StringBlock.getShort(StringBlock.java:231) at android.content.res.StringBlock.getString(StringBlock.java:91) at android.content....

    AXMLPrinter2ME.S.jar

    在http://download.csdn.net/detail/rowangame/9023311的基础上,增加忽略Magic Number和判断StyleOffset大小的语句,避免因修改Magic Number导致的解析错误,以及错误的StyleOffset导致的EOF Exception。

    AXMLPrinter

    用来查看apk中的AndroidManifest.xml文件的工具,使用方法在jar包中的readme

    AXMLPrinter2反编译错误

    java.lang.ArrayIndexOutOfBoundsException: 128 at android.content.res.StringBlock.getShort(StringBlock.java:231) at android.content.res.StringBlock.getString(StringBlock.java:91) at android.content....

    java编程常见问题

    42.java.lang.ArrayIndexOutOfBoundsException 数组索引越界异常。当对数组的索引值为负数或大于等于数组大小时抛出。 43.java.lang.ArrayStoreException 数组存储异常。当向数组中存放非数组声明类型对象时抛出。 ...

    AndroidManifest.xml 最新解析包

    AXMLPrinter-latest.jar解决解析AndroidManifest.xml时候,出现异常 java.lang.ArrayIndexOutOfBoundsException: 588

    AXMLPrinter2.jar

    解决AXMLPrinter2反编译的时。 java.lang.ArrayIndexOutOfBoundsException: 128 的报错问题

    AXMLPrinter2修改版

    解决AXMLPrinter2反编译的时候报错 java.lang.ArrayIndexOutOfBoundsException: 128

    AXMLPrinter2修正版本

    java.lang.ArrayIndexOutOfBoundsException: 128 at android.content.res.StringBlock.getShort(StringBlock.java:231) at android.content.res.StringBlock.getString(StringBlock.java:91) at android.content....

Global site tag (gtag.js) - Google Analytics