0

我是 java 新手,我从 wikibooks 下载了一个 pdf 文档,在尝试运行程序时出现以下错误:

Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException: 0
at Distance.main(Distance.java:7)

这是我试图运行的代码:

public class Distance
{
    private java.awt.Point point0, point1;
    public Distance(int x0, int y0, int x1, int y1)
    {
        point0 = new java.awt.Point(x0, y0);
        point1 = new java.awt.Point(x1, y1);
    }

    public void printDistance()
    {
        System.out.println("Distance between " + point0 + " and " + point1
            + " is " + point0.distance(point1));
    }

    public static void main(String[] args)
    {
        Distance dist = new Distance(
        intValue(args[0]), intValue(args[1]),
        intValue(args[2]), intValue(args[3]));
        dist.printDistance();
    }

    private static int intValue(String data)
    {
        return Integer.parseInt(data);
    }
}
4

1 回答 1

6

您没有在命令行 java 调用或 IDE 配置中提供参数。

它似乎需要四个整数参数,如:

java Distance 0 1 2 3
于 2012-12-14T15:06:34.587 回答