首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > JAVA > Java Exception >

java.lang.ArrayIndexOutOfBoundsException: 0解决方法!

2014-01-26 
public class hao { public static void main(String args[]) {int month monthShort.parseShort(args[0]

public class hao {
public static void main(String args[])
{int month;
month=Short.parseShort(args[0]);
switch(month)
{case 1:System.out.println("January");break;
case 2:System.out.println("February");break;
case 3:System.out.println("March");break;
case 4:System.out.println("April");break;
case 5:System.out.println("May");break;
case 6:System.out.println("June");break;
case 7:System.out.println("July");break;
case 8:System.out.println("August");break;
case 9:System.out.println("September");break;
case 10:System.out.println("Octember");break;
case 11:System.out.println("November");break;
case 12:System.out.println("December");break;
}
}
}
我运行了这个程序  编译时 生成成功  但是执行时却出现
Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException: 0
at hao.main(hao.java:4)

请问这是怎么回事啊 ?
------解决方法--------------------------------------------------------
运行的时候有没有加参数?没有的话,到哪里去拿args[0]
------解决方法--------------------------------------------------------
要么在运行前配制参数,要么在运行时读取输入的参数,没有参数args[0]肯定会数组越界拉!
------解决方法--------------------------------------------------------
Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException: 0
-->这个是数组下标越界的运行时错误

month=Short.parseShort(args[0]); 语句中用到了args[0],即接受从键盘传入的String参数。
在运行该类时,应该在后面加上参数,比如:java hao August

------解决方法--------------------------------------------------------
数组下标越界,你没有参数.
------解决方法--------------------------------------------------------
数组是空的,当然出现越界了,你给数组赋值就好了
------解决方法--------------------------------------------------------
调用以前先判断 args[]是不是null...

        

热点排行