public class hanoi {
    static void moves(char a, char c){
     System.out.println("From "+a+"To"+c);
    }
    
    static void hanoijudge(int n, char a, char b , char c){
     if( n == 1 )
     moves(a,c);
     else{
     hanoijudge(n-1,a,c,b);
     moves(a,c);
     hanoijudge(n-1,b,a,c);
     }
    }
    public static void main(String[] args){
        int n ;
        n =  Integer.parseInt(args[0]);
        hanoijudge(n,'A','B','C');
    } 
    
}Eclipse运行 显示 ARG数组索引越界异常,菜鸟看不出错啊,求帮助

解决方案 »

  1.   

    n = Integer.parseInt(args[0]);
    你用到了命令行参数,在eclipse的Run As--->Run confiruation-->Arguments里面配置下,否则没有参数肯定数组越界啊
      

  2.   

    你eclipse运行的时候没有设置 程序运行的参数,导致args这个字符串数组是null,调用n = Integer.parseInt(args[0]);的时候就报数组越界了
    如果要继续用n = Integer.parseInt(args[0]);这一行,那么可以在eclipse里面设定,中文版:
      1、打开“运行”菜单,点击“运行(N)...”按钮,进入运行配置界面。
      2、在左侧选择要运行的程序,然后点击右侧“(x)=自变量”标签,在下面的“程序自变量(A):”文本框中输入程序运行需要的参数。
      3、点击下面的“运行(R)”按钮运行程序。    英文版:
      1、打开“Run”菜单,点击“Run...”按钮,进入运行配置界面。
      2、在左侧选择要运行的程序,然后点击右侧“(x)=Arguments”标签,在下面的“Program arguments:”文本框中输入程序运行需要的参数。
      3、点击下面的“Run”按钮运行程序。 
    -
    文章转载自网管之家:http://www.bitscn.com/pdb/java/200711/120266.html
      

  3.   

    谢谢啊! 可是 VM arguements 里面参数要怎么设置?
      

  4.   

    Eclipse上面有个run选项,里面可以设置在运行时,传个值进来!
       你一定是那里没有传值,所以报空异常咯!
      

  5.   

    是VM arguement里面写么,具体应该怎么写呢,初次接触JAVA还不清楚,不好意思
      

  6.   

    int n ;
      n = Integer.parseInt(args[0]);
    其实可以换成Scanner console = new Scanner(System.in);
    int n = console.nextInt();上面的意思,在控制台中从键盘接收数据。就是在控制台你敲个数,这样你就不许配置参数了,直接运行就可以。public class Test { public static void main(String[] args) {
    System.out.println("楼主开始啦。");
    while(true){
    Scanner console = new Scanner(System.in);
    String line = console.nextLine();
    if("bye".equals(line)){
    System.out.println("楼主你输入的是:bye,所以现在要退出了");
    }else{
    System.out.println("楼主你输入的是:"+line+" 请继续。");
    }
    }
    }
    }
      

  7.   

    VM arguements 这也是个IDE么? 没见过