• Post Reply Bookmark Topic Watch Topic
  • New Topic

Another error  RSS feed

 
Nicola Guy
Ranch Hand
Posts: 91
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi there as some people may know today I am trying to read and write to text files. However, I've been getting this error message for a while:

java.lang.NullPointerException
java.io.Writer.write(Writer.java:126)
app.UserAction.perform(UserAction.java:127)
org.apache.struts.action.ActionServlet.processActionPerform(ActionServlet.java:1787)
org.apache.struts.action.ActionServlet.process(ActionServlet.java:1586)
org.apache.struts.action.ActionServlet.doPost(ActionServlet.java:510)
javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
javax.servlet.http.HttpServlet.service(HttpServlet.java:810)

The bit of code that is generating is :

String newfile;
newfile = readFile();
String doc = getFirstName();

BufferedWriter output = null;
output = new BufferedWriter( new FileWriter(file) );
==> output.write(doc);
output.close();


The method readfile reads the current values in the text file and when I replace doc with newfile it works fine. The method getFirstName is simply:

public String getFirstName() {
return firstName;
}

I really can't see the problem

thanx in advance
 
Ernest Friedman-Hill
author and iconoclast
Sheriff
Posts: 24217
38
Chrome Eclipse IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
THe NullPointerException from write() means that the argument you're passing is null -- i.e., getFirstName() is returning null, which means the firstName member is null. Check the code that you think should be setting that member variable.
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!