[Solved] Why does it keep returning “null”? [closed]


You did not call the method ReadTextFile thus giving you error NPE.

solution call the ReadTextFile method first

FirstIO l= new FirstIO();
l.ReadTextFile();
System.out.println(comein);

Another solution

you can do it in the FirstIO constructor so you wont call the method

public class FirstIO{
static BufferedReader comein;

public FirstIO(){
    try {
    comein= new BufferedReader(new FileReader("C:\Users\HP\Desktop\vocab.txt"));
    } catch(IOException ioe){
        System.out.println("File Not Found");
    }
}
public static void main(String[] args){

    FirstIO l= new FirstIO();
    System.out.println(comein);
}

}

3

solved Why does it keep returning “null”? [closed]