线程" main"中的例外情况

时间:2016-01-23 05:35:43

标签: java

这是我的代码。输出应为32.9。但它似乎显示

  

线程中的异常" main" java.lang.NullPointerException at   ArrayLocation.main(ArrayLocation.java:14)

public class ArrayLocation {
    private double coords[];

    public ArrayLocation(double[] coods){
        this.coords=coords;
    }

    public static void main(String[] args){
        double[] coords={5.0,0.0};
        ArrayLocation accra= new ArrayLocation(coords);
        coords[0]=32.9;
        coords[1]=-117.2;
        System.out.println(accra.coords[0]);
    }
}

1 个答案:

答案 0 :(得分:2)

您的代码中存在拼写错误。

更改

public ArrayLocation(double[] coods) {

public ArrayLocation(double[] coords) {