-2

i´ve been trying to read the lines of this file to save them into an array afterwards, but when I try to print the lines to try it out it has a nullpointer on the line of :

while( (line = br.readLine()) !=null

import java.io.BufferedReader;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.IOException;

public class Main1 {

    public static void main(String[] args) {
        // TODO Auto-generated method stub
        String line;
        BufferedReader br = null ;
        try {
            new BufferedReader(new FileReader("/Users/Daniq/Desktop/eda/pruebaEda.txt"));
            System.out.println("Done");

            try {
                while( (line = br.readLine()) != null){
                    System.out.println(line);
                }
            } catch (IOException e) {
                // TODO Auto-generated catch block
                System.out.println("error ");
            }

        } catch(FileNotFoundException fnfex){
            System.out.println("File not found");
        }

    }

}
rptmat57
  • 3,643
  • 1
  • 27
  • 38
daniqt2
  • 83
  • 1
  • 4
  • 1
    You declared `BufferedReader br` assigned `null` to it via `= null` but then never assign proper BufferedReader to `br` so it is still holding `null` which doesn't have `readLine` method. You need `br = new BufferedReader(...);` – Pshemo Mar 25 '17 at 13:20

1 Answers1

1

You dont initalize br reference, after try,

br = new BufferedReader...
Mustafa Çil
  • 766
  • 8
  • 15