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

Exception in thread "main" java

2011-12-18 
Exception in thread main java.class ck {/** * @param args */public static void main(String[] args

Exception in thread "main" java.

 class ck {

/**
* @param args
*/
public static void main(String[] args) {
// TODO Auto-generated method stub
 int n=Integer.parseInt(args[0]);
 for(int i=1;i<=n;i++)
 {
for(int k=n;k>=i;k--)
  {
System.out.print(" ");
 
  }
 for(int j=1;j<=2*i-1;j++)
  {
System.out.print("*");
 
  }
 System.out.println();
 }
   
}

}

这个错误怎么解决  
Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException: 0
at ck.main(ck.java:9)


[解决办法]
数组角标溢出
[解决办法]
溢出的原因是数组没有初始化 args[0]里面没有东西
[解决办法]
3#解释的没错,你可以在CMD里输入 java ck 4 看看输出的是什么

还有类名首字母最好大写 呵呵
[解决办法]
先搞清楚args是什么东东再用吧,然后异常已经说得很清楚:
ArrayIndexOutOfBoundsException
数组 下标 超出界限 异常

你要是了解args是怎么来的,就知道为什么越界了,有些东西还是要寻根问底的.

热点排行