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数组中还没值,如果取它的第一个值,那肯定是数组越界异常。
可以先判断:if(args.length!=0)

1、应该这样运行:java  test.Test  参数
2、如果在Eclipse中运行的话:

  run->run configurations...->argumens

  在这个里面输入运行时参数,若有多个参数以空格隔开。

参考链接:http://www.iteye.com/problems/35147

java 中 java.lang.ArrayIndexOutOfBoundsException: 0 异常的更多相关文章

  1. Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException: 0

    Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException: 0 at ExTestDrive.main ...

  2. 解决Redisson出现Failed to instantiate [org.redisson.api.RedissonClient]: Factory method 'create' threw exception; nested exception is java.lang.ArrayIndexOutOfBoundsException: 0的问题

    一.背景 最近项目中使用了redisson的哨兵模式来作为redis操作的客户端,然后一个意外出现了,启动报:Failed to instantiate [org.redisson.api.Redis ...

  3. java中常见的几种异常

    算术异常类:ArithmeticExecption空指针异常类:NullPointerException类型强制转换异常:ClassCastException数组负下标异常:NegativeArray ...

  4. JAVA中double类型运算结果异常的解决

    问题: 对两个double类型的值进行运算,有时会出现结果值异常的问题.比如: System.out.println(19.99+20); System.out.println(1.0-0.66); ...

  5. JAVA中java.lang.OutOfMemoryError常见的解决方式

    在开发中我们很多人都遇到过内存溢出的情况,其实内存溢出分几种形式: 1.tomcat中java.lang.OutOfMemoryError: PermGen space异常处理(最常见的) 概念大家可 ...

  6. 在java中使用solr7.2.0 新旧版本创建SolrClient对比

    在Java中使用solr 版本7.2.0 solrj已经更新到了7.2.0,新版本solr获取SolrClient的方式也和之前旧版本有所不同 solr6.5开始不推荐直接使用HttpSolrClie ...

  7. java中 Java.lang.Long.parseLong()方法

    这是在刷杭电一道水题中遇到的,当时用java没思路,便查了查题解,用到了Java.lang.Long.parseLong()方法 题目链接:http://acm.hdu.edu.cn/showprob ...

  8. 关于java中为什么尽量把受检异常转化为非受检异常

    首先理解一下受检异常与非受检异常: 异常表示程序运行过程中可能出现的非正常状态,运行时异常表示虚拟机操作中可能遇到的异常,是一种常见的运行错误,只要程序设计的没有问题通常就不会发生.受检异常与程序的上 ...

  9. Java中BigDecimal的一个除法异常

    java.lang.ArithmeticException: Non-terminating decimal expansion; no exact representable decimal res ...

随机推荐

  1. POJ1979 Red and Black (简单DFS)

    POJ1979 Description There is a rectangular room, covered with square tiles. Each tile is colored eit ...

  2. Jsp:useBean标签的使用

    1.<jsp:useBean id="为Bean起的别名(随意起)" class="Bean的目录,从包名开始写" scope="page | ...

  3. cocos2d-x 3.x丨搭建Android环境下的开发环境

    所需要的一些工具软件: 1.JDK  官网下载地址:http://www.oracle.com/ttechnetwork/java/javase/downloads/index.html 2.Andr ...

  4. 统计Crash工具—Crashlytics

    官网:https://www.crashlytics.com/login 步骤: 注意:有时候再次运行,或者换了Crashlytics账号之后,获取不到Crash信息,其实你需要把plist文件里的K ...

  5. 图的强连通分量-Kosaraju算法

    输入一个有向图,计算每个节点所在强连通分量的编号,输出强连通分量的个数 #include<iostream> #include<cstring> #include<vec ...

  6. 使用HTTP协下载文件

    通过发送HTTP请求,下载文件 头文件: #ifndef __HTTP__ #define __HTTP__ #include <stdio.h> #include <stdlib. ...

  7. ASPXGridView用法

    一.ASPXGridView外观显示 属性: Caption----列的标题( KeyFieldName----数据库字段 SEOFriendly 是否启用搜索引擎优化 Summary 指定分页汇总信 ...

  8. C#中如何判断联系电话的合法性

    string tel = tb_tel.Text.Trim();//联系电话if (!string.IsNullOrEmpty(tb_tel.Text.Trim())){try{//num = Con ...

  9. 【ITOO 2】使用ArrayList时的注意事项:去除多余的null值

    问题描述:在课表导入的时候,将数据从excel表里读出,然后将list批量插入到对应的课程表的数据表单中去,出现结果:当我们导入3条数据时,list.size()为3,但是实际上,list里面存在10 ...

  10. extern “C”调用测试与验证-2016.01.06

    1 调用情形说明 在上一篇关于extern “c”原理以及用法中,详细的说明了为什么需要extern “c”以及如何使用它解决c与c++混合编程时遇到的问题.接下来,使用示例验证方式验证c与c++函数 ...