I’m getting a NullPointerException on a line where I call a method and pass it a string. I can only assume the string is null.
It was initialised from a BufferedReader readline a few lines before. Here’s the relevant code:
FileInputStream tmp = null;
try {
tmp = new FileInputStream(file);
} catch (FileNotFoundException e) {
System.err.println("File not found!");
e.printStackTrace();
System.exit(1);
}
DataInputStream dis = new DataInputStream(tmp);
BufferedReader br = new BufferedReader(new InputStreamReader(dis));
create();
try {
data = br.readLine();
} catch (IOException e) {
System.err.println("First readline failed: " + e);
System.exit(1);
}
while (!data.equals(null)) {
process(data);
...
and the error:
Exception in thread "main" java.lang.NullPointerException
at enc.read(enc.java:40)
at enc.main(enc.java:15)
Your nullness check itself triggers the
NullPointerException. Instead of!data.equals(null)writedata != null.