I am trying to add a comment with in an XML file using JDOM. But everytime the code get to the comment.setText(comments) it throws a NullPointerException. Well part of the code i am giving you guys here.... Please take a look and let me know where the problem lies.
Comment comment = null;
String comments = "This is a comment";
When it comes to the line "comment.setText(comments);". It throws a NullPointerException. I am using Eclipse. I get a warning that the command would throw a NullPointerException. But I am unable to prevent it. Please help.
But this isn't really an XML question. It's a beginning Java question. You have a variable which is null, then you try to use it as if it had an object assigned to it. But it doesn't, so you get a NullPointerException.
Just assign an object to the variable. Your JDOM documentation should tell you how to create a new Comment object, and that's all you need.