0

Here is my code. the output should be 32.9. But it seems showing

Exception in thread "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]);
    }
}
David Maust
  • 8,080
  • 3
  • 32
  • 36
Zzw TOM
  • 25
  • 4
  • `this.coords=coords;` -> Check this line... That's why you should use an IDE and give attention to warnings too... – Codebender Jan 23 '16 at 05:40

1 Answers1

2

There is a typo in your code.

Change

public ArrayLocation(double[] coods) {

to

public ArrayLocation(double[] coords) {
sinclair
  • 2,812
  • 4
  • 24
  • 53