I have a jsp/servlet/JDBC application deployed on Tomcat 5.5. At the work place it runs fine without problems but at home I get
a Nullpointer Exception. I even tarred up the entire tomcat directory at work with the application and moved it to my system at home and got the same problem.
I have worked on this for 3 weeks still I cannot get the application to work at home neither have I been able to fish out what the problem is.
Please has anyone encoutered this before ? I will appreciate some directions here.
thanks
jones
Bauke Scholtz
Ranch Hand
Joined: Oct 08, 2006
Posts: 2458
posted
0
In fact you just need to look at the first line of the stacktrace of the NPE to find out the class/method/codeline where it is been thrown and finally fix the code logic/flow accordingly.
Do you understand at any way when a NPE would occur and how you could fix it?
jonas, just saying "I get an error" isn't enough information for use to help you. We need to see the details of the error message and of the code that's causing it. Please read this for more information.
The NPE:
SEVERE: Servlet.service() for servlet Register threw exception
java.lang.NullPointerException at Uxdomain.StudentDAO.insert(StudentDAO.java:19)
at Uxweb.RegistrationServlet.processRequest(RegistrationServlet.java:51)
at Uxweb.RegistrationServlet.doPost(RegistrationServlet.java:26)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:647)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:729)
The Data Access Class:
My DAO data access code:
public void insert(String name, String phone, String email, String gender, String amountpaid) {
try {
Connection conn = null;
conn= connPool.mysqlConnection();
PreparedStatement stmt = conn.prepareStatement(INSERT_STMT);
stmt.setString(1, name);
stmt.setString(2, phone);
stmt.setString(3, email);
stmt.setString(4, gender);
stmt.setString(5, amountpaid);
stmt.executeUpdate();
You didn't have read my link at all and you actually don't understand at all when a NPE will be thrown? That's too bad.
You know that you can assign null to a reference, do you?
Can you tell what will happen when you invoke s.length() or any other method on that? Can you also explain why that happens?
The same is happening in your code. It's very simple, one of the most simplest exceptions to hunt and solve. The first line of the stacktrace tells that it's the line 19 of StudentDAO class, inside the insert() method where an object reference is been invoked while it is null. Fixing it is simple: just make sure that it is not null, or bypass the invocation.
jonas okwara
Ranch Hand
Joined: Jun 22, 2004
Posts: 58
posted
0
Bauke, Bear and Balu,
I really appreciate your direction and good words. Bauke I have printed that excellent article at 0xCAFEFEED and will certainly keep me engaged this weekend. I have been worked up by my failure to resolve this that I failed to see the error right under my nose.
Thanks again
jones
I agree. Here's the link: http://ej-technologies/jprofiler - if it wasn't for jprofiler, we would need to
run our stuff on 16 servers instead of 3.