从命令行调用程序

时间:2013-11-09 18:55:01

标签: java eclipse terminal

我有一个来自Algorithms类的类:

public class Counter {
    private final String name;
    private int count;

    public Counter(String id) {
        name = id;
    }

    public void increment(){
        count++;
    }

    public int tally(){
        return count;
    }

    public String toString(){
        return count + " " + name;
    }


    public static void main(String[] args) {
        Counter heads = new Counter("heads");
        Counter tails = new Counter("tails");
        heads.increment();
        heads.increment();
        tails.increment();

        StdOut.println(heads + " " + tails); 
        StdOut.println(heads.tally() - tails.tally());
    }
}

当我在Eclipse中运行它时工作正常,但当我在终端中使用:

调用它时
java -cp '../jar/algs4.jar:../jar/stdlib.jar' Counter

它返回

Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException: 0
    at Counter.main(Counter.java:79)

为什么?

0 个答案:

没有答案