Need help with NullPointerException in servlet

Hi guys , I have a servlet called submit servlet ,which instantiates a DataAccessObject called LetterRequestDAO and stores a letter using that.

Here is the part of my code that does that.

letterList =null;

LtrDAO =new LetterRequestDAO("001");

LtrDAO.storeLetter(EID);

letterList = LtrDAO.getLetterList();

I have imported the package that LetterrequestDAO belongs to using

import com.letterrequest.DAOs.LetterRequestDAO;

I checked the LetterrequestDAO (I inserted a main method in it and ran it)and its not throwing any null pointerException .Its storing the Letter and retreiving the ArrayList with no problem .

The program highlights at

LtrDAO.storeLetter(EID); when the null pointer exception is thrown .What could be the problem ?Why is my servlet not able to instantiate LetterrequestDAO ?Any ideas .I'm stuck with this problem for a week now.I really appreciate any suggestions .

I can post the two programs if it wont annoy anyone .

Thanks a bunch ,

Kavita

[1176 byte] By [KRiveraa] at [2007-10-2 11:47:55]
# 1
Could you paste the stack trace of the excpetion.
rakeshsua at 2007-7-13 6:05:23 > top of Java-index,Developer Tools,Debugging and Profiling Tool APIs...
# 2

Hi ,

Here is the stack trace. You will see that the connection in showing up as null .But when I put a main() method in LetterRequestDAO , I am able to get the connection .If I use LetterRequestDAO from SubmitServlet , I am not able to get the connection

.Kavita

[2/9/06 11:13:52:777 EST] 53d1373d WebGroupI SRVE0180I: [LTRWEB] [/LTRWEB] [Servlet.LOG]: SubmitServlet: init

[2/9/06 11:13:52:817 EST] 53d1373d SystemOutO Employee ID in else part of submit servlet is 5

[2/9/06 11:13:52:877 EST] 53d1373d SystemOutO Connection madenull

[2/9/06 11:13:52:877 EST] 53d1373d SystemOutO LtrDAO is instantiated

[2/9/06 11:13:52:877 EST] 53d1373d SystemOutO In storeLetter -in try block before setting String qs

[2/9/06 11:13:52:877 EST] 53d1373d SystemOutO In storeLetter -in try block after setting String qs

[2/9/06 11:13:52:877 EST] 53d1373d SystemOutO connection in LetterRequestDAO is null

[2/9/06 11:13:53:327 EST] 53d1373d WebGroupE SRVE0026E: [Servlet Error]-[SubmitServlet]: java.lang.NullPointerException

at com.letterrequest.DAOs.LetterRequestDAO.storeLetter(LetterRequestDAO.java:39)

at com.letterrequest.servlets.SubmitServlet.doPost(SubmitServlet.java:50)

at javax.servlet.http.HttpServlet.service(HttpServlet.java:760)

at javax.servlet.http.HttpServlet.service(HttpServlet.java:853)

at com.ibm.ws.webcontainer.servlet.StrictServletInstance.doService(StrictServletInstance.java:110)

at com.ibm.ws.webcontainer.servlet.StrictLifecycleServlet._service(StrictLifecycleServlet.java:174)

at com.ibm.ws.webcontainer.servlet.IdleServletState.service(StrictLifecycleServlet.java:313)

at com.ibm.ws.webcontainer.servlet.StrictLifecycleServlet.service(StrictLifecycleServlet.java:116)

at com.ibm.ws.webcontainer.servlet.ServletInstance.service(ServletInstance.java:283)

at com.ibm.ws.webcontainer.servlet.ValidServletReferenceState.dispatch(ValidServletReferenceState.java:42)

at com.ibm.ws.webcontainer.servlet.ServletInstanceReference.dispatch(ServletInstanceReference.java:40)

at com.ibm.ws.webcontainer.webapp.WebAppRequestDispatcher.handleWebAppDispatch(WebAppRequestDispatcher.java:1019)

at com.ibm.ws.webcontainer.webapp.WebAppRequestDispatcher.dispatch(WebAppRequestDispatcher.java:592)

at com.ibm.ws.webcontainer.webapp.WebAppRequestDispatcher.forward(WebAppRequestDispatcher.java:204)

at com.ibm.ws.webcontainer.srt.WebAppInvoker.doForward(WebAppInvoker.java:125)

at com.ibm.ws.webcontainer.srt.WebAppInvoker.handleInvocationHook(WebAppInvoker.java:286)

at com.ibm.ws.webcontainer.cache.invocation.CachedInvocation.handleInvocation(CachedInvocation.java:71)

at com.ibm.ws.webcontainer.srp.ServletRequestProcessor.dispatchByURI(ServletRequestProcessor.java:182)

at com.ibm.ws.webcontainer.oselistener.OSEListenerDispatcher.service(OSEListener.java:334)

at com.ibm.ws.webcontainer.http.HttpConnection.handleRequest(HttpConnection.java:56)

at com.ibm.ws.http.HttpConnection.readAndHandleRequest(HttpConnection.java:615)

at com.ibm.ws.http.HttpConnection.run(HttpConnection.java:439)

at com.ibm.ws.util.ThreadPool$Worker.run(ThreadPool.java:912)

KRiveraa at 2007-7-13 6:05:23 > top of Java-index,Developer Tools,Debugging and Profiling Tool APIs...
# 3
Try finding what makes the connection null. It must be throwing some kind of exception which is caught but eventually null is returned.
rakeshsua at 2007-7-13 6:05:23 > top of Java-index,Developer Tools,Debugging and Profiling Tool APIs...
# 4
Hello,First let me apologize for I am not answering to your question. I saw in a previous post that you were trying to connect Mysql with WSAD through JDBC. I am trying the same with no success.Could you successfully get the connection?ThanksGunjan
StartingWithJ2EEa at 2007-7-13 6:05:23 > top of Java-index,Developer Tools,Debugging and Profiling Tool APIs...
# 5

Hi Gunjan , As a last resort , I right clicked on WEB-INF-classes and clicked -import zip files and imported the mySqlconnector file that we had . It directly placed it into the manifest file.

I know this is the wrong way to do it , but it worked .

I didnt set any dataSources.

Kavita

KRiveraa at 2007-7-13 6:05:23 > top of Java-index,Developer Tools,Debugging and Profiling Tool APIs...
# 6
Thanks.GunjanPS: After a lot of research I was successful in getting the connection!
StartingWithJ2EEa at 2007-7-13 6:05:23 > top of Java-index,Developer Tools,Debugging and Profiling Tool APIs...