Null Pointer Exception. How to fix this problem?
I'm a newbie coder, programmer, computer science student.
My project just received this error called null pointer exception.
Code :
java.lang.NullPointerException
servlet.AddRewardsPages.doPost(AddRewardsPages.java:119)
javax.servlet.http.HttpServlet.service(HttpServlet.java:647)
javax.servlet.http.HttpServlet.service(HttpServlet.java:728)
note The full stack trace of the root cause is available in the Apache Tomcat/7.0.34 logs.
How to get rid of this, so that my project works well?
Re: Null Pointer Exception. How to fix this problem?
Go to line number 119 (as clearly mentioned in the stacktrace) of your servlet class named AddRewardsPages.java and check for the variable in that line which is used. That variable must be null. Try printing the variable and run the application again so as to see what it is returning.
Re: Null Pointer Exception. How to fix this problem?
Quote:
Originally Posted by
Pratyush
Go to line number 119 (as clearly mentioned in the stacktrace) of your servlet class named AddRewardsPages.java and check for the variable in that line which is used. That variable must be null. Try printing the variable and run the application again so as to see what it is returning.
Thanks.
I'll get right on it.
--- Update ---
Quote:
Originally Posted by
carbLoading2012
Thanks.
I'll get right on it.
Wait, what exactly do you mean to print it?
Here is my code where this is happening
Code :
if (valid) {
Reward reward = new Reward(new Integer(pledgeAmount), rewardDescription, request.getSession(true).getAttribute("USER").toString());
Line 119. --> project.addReward(reward);
request.getSession(true).setAttribute("PROJECT", project);
pledgeAmount = "";
rewardDescription = "";
}
}
--- Update ---
Alright...
I received the error on a different part of the application...
Code :
ava.lang.NullPointerException
servlet.Projects.doGet(Projects.java:171)
servlet.Projects.doPost(Projects.java:201)
javax.servlet.http.HttpServlet.service(HttpServlet.java:641)
javax.servlet.http.HttpServlet.service(HttpServlet.java:722)
servlet.AddReward.doPost(AddRewardsPages.java:68)
javax.servlet.http.HttpServlet.service(HttpServlet.java:641)
javax.servlet.http.HttpServlet.service(HttpServlet.java:722
What do I do with this?
The same thing that was recommended in a previous thread.