I am creating a HTML Webpage Generator as part of a college assignment. What I am trying to do is set the header by taking in the users text and saving it to string through the use of a get / set class. However when I try to output the text to file I get an error.
The code I am using to try and output the string is the following
public static void main(String[] args) throws IOException {
try {
File f = new File("C:\\Users\\David\\Desktop\\output.html");
if(!f.exists()) {
f.createNewFile();
}
FileWriter fw = new FileWriter(f);
fw.write(getHeader());
fw.close();
}catch(IOException io) {
Logger.getLogger(webPage.class.getName()).log(Level.SEVERE, null, io);
}
}
The error that Eclipse is giving me is
Exception in thread "main" java.lang.NullPointerException
at java.io.Writer.write(Unknown Source)
at webPage.main(webPage.java:49)
Can anyone help me correct this please?