Null Pointer Exception with BufferedWriter
Hi Guys,
The code below is throwing a Null Pointer Exception at this line:
Code:
out = new BufferedWriter(fw);
and I can’t work out why. I first thought it was to do with scope, but after fiddling with the declarations it didn’t make any difference. It's like it can't see what the out object is or something.
Could you please have a look and let me know?
Thanks :)
Code:
import java.io.*;
public class Storage {
protected File file;
protected String path = "C:/Users/Chicky/Documents/NetBeansProjects/Drive/Input";
protected String filepath = "C:/Users/Chicky/Documents/NetBeansProjects/Drive/Input/Data.csv";
protected FileWriter fw;
protected BufferedWriter out;
public void Storage(){
}
protected void setup() throws IOException{
file = new File(path);
if(!file.isDirectory()){
file.mkdir();
fw = new FileWriter(filepath, true);
}
else if(file.isDirectory() && file.exists()){
//don't want to do anything here
}
out = new BufferedWriter(fw);
}
...
...