user2287768
user2287768

Reputation: 13

why this method is giving a null pointer exception

this code is supposed to read from a file and parse each entry as a double in the point array it successfully reads from the file but whenever it tries to parse the input tp double it give null pointer exception .

 try {
        BufferedReader br = new BufferedReader(new    FileReader("dataset.csv"));
        int j = 0;

        while ((line = br.readLine()) != null) {
            String [] pointtemp = line.split(split);
            //check
            point = new double[point.length];
            for (int i = 0; i< pointtemp.length; i++){
                point[i] = Double.parseDouble(pointtemp[i]);
                System.out.println(point[i]);
            }
            points [j] = new point(point);
            j++;


    }

Upvotes: 0

Views: 79

Answers (2)

ItayB
ItayB

Reputation: 11337

try to surround it with try & catch mechanism and print (in catch) the value of pointtemp[i]. Maybe you are trying to parse an empty cell ?

Upvotes: 0

Masudul
Masudul

Reputation: 21961

Your double[] initialization is not correct. Declare it as

   point = new double[pointtemp.length];

Upvotes: 4

Related Questions