这是我的代码。输出应为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]);
}
}
答案 0 :(得分:2)
您的代码中存在拼写错误。
更改
public ArrayLocation(double[] coods) {
到
public ArrayLocation(double[] coords) {