• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Tim Cooke
  • Campbell Ritchie
  • Ron McLeod
  • Liutauras Vilda
  • Jeanne Boyarsky
Sheriffs:
  • Junilu Lacar
  • Rob Spoor
  • Paul Clapham
Saloon Keepers:
  • Tim Holloway
  • Tim Moores
  • Jesse Silverman
  • Stephan van Hulst
  • Carey Brown
Bartenders:
  • Al Hobbs
  • Piet Souris
  • Frits Walraven

protected Map referenceData(HttpServletRequest request) is giving me null pointer exception

 
Greenhorn
Posts: 13
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi all,

Kindly help me to resolve the problem given below.
I am working in Spring Web MVC . I n one of my forms i have a list which has to be populated from the database.



And my service layer is as below:


Implementation class:


My dao for jdbc



And in my addEditProject.jsp , i am using


The above code works fine , IF i am using a dummy list of addresses as below in the controller class:


But the same fails and throws a nullpointer exception when trying to populate from the database.

Except for the population of lists, i am able to add, update in my application.

Please someone help me as it is urgent for my project.

I have not yet received any answers for my previous posts . But somehow i managed to overcome the problem.
Kindly look into this problem.

Regards,
Nikhitha
 
Rancher
Posts: 2759
32
Eclipse IDE Spring Tomcat Server
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
It would help us help you tremendously if you post the stack trace from the NullPointerException
 
Bartender
Posts: 4568
9
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
The point being that the stack trace will tell you - and us - exactly which line throws the exception.
 
Nikhy Pai
Greenhorn
Posts: 13
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
OK. Here is the stack trace.

SEVERE: Servlet.service() for servlet [apple] in context with path [/ApplewithDate] threw exception [Request processing failed; nested exception is java.lang.NullPointerException] with root cause
java.lang.NullPointerException
at net.apple.web.AddEditProjectFormController.referenceData(AddEditProjectFormController.java:111)
at org.springframework.web.servlet.mvc.SimpleFormController.referenceData(SimpleFormController.java:218)
at org.springframework.web.servlet.mvc.AbstractFormController.showForm(AbstractFormController.java:578)
at org.springframework.web.servlet.mvc.SimpleFormController.showForm(SimpleFormController.java:201)
at org.springframework.web.servlet.mvc.SimpleFormController.showForm(SimpleFormController.java:178)
at org.springframework.web.servlet.mvc.AbstractFormController.showNewForm(AbstractFormController.java:341)
at org.springframework.web.servlet.mvc.AbstractFormController.handleRequestInternal(AbstractFormController.java:281)
at org.springframework.web.servlet.mvc.AbstractController.handleRequest(AbstractController.java:153)
at org.springframework.web.servlet.mvc.SimpleControllerHandlerAdapter.handle(SimpleControllerHandlerAdapter.java:48)
at org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:771)
at org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:716)
at org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:647)
at org.springframework.web.servlet.FrameworkServlet.doGet(FrameworkServlet.java:552)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:621)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:728)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:305)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210)
at org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:243)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:222)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:123)
at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:502)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:171)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:100)
at org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:953)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:118)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:409)
at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1044)
at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:607)
at org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:313)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1110)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:603)
at java.lang.Thread.run(Thread.java:722)


That is all i have. Hope it would be of help.
 
Jayesh A Lalwani
Rancher
Posts: 2759
32
Eclipse IDE Spring Tomcat Server
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Nikhy Pai wrote:
java.lang.NullPointerException
at net.apple.web.AddEditProjectFormController.referenceData(AddEditProjectFormController.java:111)



What's the line of code in line 111 of AddEditProjectFormController?. A NPE is usually generated when you try to call a function on a reference that is null. You must be using a reference that is null on that line.
 
Nikhy Pai
Greenhorn
Posts: 13
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi thank you for pointing out that.
The line 111 in AddEditProjectFormController is
referenceData.put("addresses", addressService.getAllAddressIds());

i am a bit confused about the returned data and the type from the method addressService.getAllAddressIds());

Actually I am getting this result in AddressDAOJdbc. What i get as a result of this , i have called this method in AddEditProjectFormController.
The actual implementation of this is done in Package ---- net.apple.dao.jdbc, which contains two classes AddressDAOJdbc and ProjectDAOJdbc.

Domain object in Address - 2 fields address_id, address_desc and other fields.
Domain object for Project - 4 fields - Proj_id, proj_desc,proj_start_dt,address_id. This address_id should be obtained from the list box which is to be populated by calling addressService.getAllAddressIds() in the reference data method.

Do I need to add the following lines in AddEditProjectFormController?
public void setAddressService(IAddressService addressService) {
this.addressService = addressService;

I am setting the projectService as it is the one which this controller is used for..

Please clear my doubt.
 
Nikhy Pai
Greenhorn
Posts: 13
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,
I also wanted to add that i have tried by modifying the method public List<Address> getAllAddressIds() in the AddressDAOJdbc class as follows:



Still i am getting the null pointer exception. Why.
It means that the reference data's call to the above method is returning null. How do i solve it ?
 
Jayesh A Lalwani
Rancher
Posts: 2759
32
Eclipse IDE Spring Tomcat Server
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Nikhy Pai wrote:Hi thank you for pointing out that.
The line 111 in AddEditProjectFormController is
referenceData.put("addresses", addressService.getAllAddressIds());




Well, obviously, referenceData cannot be null, so addressService has to be null. How have you injected addressService? Do you have an autowire annotation, or have you done property injection/ constructor injection
 
Nikhy Pai
Greenhorn
Posts: 13
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi ,

I am actually doing this spring project as a beginner. I am not using any annotations in my application.
I am not sure how to inject the addressService. Could you please help me out in that.

These are my config files

apple-dao.xml
----------------



apple-service.xml
--------------------




apple-servlet.xml
---------------------



And my web.xml is as below:


I want to tell you that If i am using AddEditAddressFormController, i am able to add, update and delete address data. But i am populating only the address_ids in the AddEditProjectFormController . How do i inject the addressService? I am sorry i sound silly.
 
Nikhy Pai
Greenhorn
Posts: 13
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi again,

Thank you. The injection was what i missed .
I have done autowire in the setter for addressService as follows now:



And my apple-servlet.xml has the following line added to it at present



I hope this is what you were suggesting.

After doing the above , now i am getting rid of the null pointer exception.
But the new exception is due to some other reason
HTTP Status 500 - org.springframework.beans.NotReadablePropertyException: Invalid property 'Address_Id' of bean class [net.apple.domain.Address]:
Bean property 'Address_Id' is not readable or has an invalid getter method: Does the return type of the getter match the parameter type of the setter?


I am attaching the stack trace below:

[net.apple.domain.Address@1339d8e]
[net.apple.domain.Address@1339d8e, net.apple.domain.Address@1acfb2d]
[net.apple.domain.Address@1339d8e, net.apple.domain.Address@1acfb2d, net.apple.domain.Address@19e7660]
[net.apple.domain.Address@1339d8e, net.apple.domain.Address@1acfb2d, net.apple.domain.Address@19e7660, net.apple.domain.Address@6db62d]
Mar 25, 2014 9:52:46 PM org.apache.catalina.core.ApplicationDispatcher invoke
SEVERE: Servlet.service() for servlet jsp threw exception
org.springframework.beans.NotReadablePropertyException: Invalid property 'Address_Id' of bean class [net.apple.domain.Address]: Bean property 'Address_Id' is not readable or has an invalid getter method: Does the return type of the getter match the parameter type of the setter?
at org.springframework.beans.BeanWrapperImpl.getPropertyValue(BeanWrapperImpl.java:665)
at org.springframework.beans.BeanWrapperImpl.getPropertyValue(BeanWrapperImpl.java:657)
at org.springframework.web.servlet.tags.form.OptionWriter.doRenderFromCollection(OptionWriter.java:202)
at org.springframework.web.servlet.tags.form.OptionWriter.renderFromCollection(OptionWriter.java:180)
at org.springframework.web.servlet.tags.form.OptionWriter.writeOptions(OptionWriter.java:133)
at org.springframework.web.servlet.tags.form.OptionsTag.writeTagContent(OptionsTag.java:168)
at org.springframework.web.servlet.tags.form.AbstractFormTag.doStartTagInternal(AbstractFormTag.java:102)
at org.springframework.web.servlet.tags.RequestContextAwareTag.doStartTag(RequestContextAwareTag.java:79)
at org.apache.jsp.WEB_002dINF.jsp.addEditProject_jsp._jspx_meth_form_005foptions_005f0(addEditProject_jsp.java:353)
at org.apache.jsp.WEB_002dINF.jsp.addEditProject_jsp._jspService(addEditProject_jsp.java:202)
at org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:70)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:728)
at org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:432)
at org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:390)
at org.apache.jasper.servlet.JspServlet.service(JspServlet.java:334)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:728)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:305)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210)
at org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:243)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210)
at org.apache.catalina.core.ApplicationDispatcher.invoke(ApplicationDispatcher.java:749)
at org.apache.catalina.core.ApplicationDispatcher.processRequest(ApplicationDispatcher.java:487)
at org.apache.catalina.core.ApplicationDispatcher.doForward(ApplicationDispatcher.java:412)
at org.apache.catalina.core.ApplicationDispatcher.forward(ApplicationDispatcher.java:339)
at org.springframework.web.servlet.view.InternalResourceView.renderMergedOutputModel(InternalResourceView.java:238)
at org.springframework.web.servlet.view.AbstractView.render(AbstractView.java:250)
at org.springframework.web.servlet.DispatcherServlet.render(DispatcherServlet.java:1060)
at org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:798)
at org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:716)
at org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:647)
at org.springframework.web.servlet.FrameworkServlet.doGet(FrameworkServlet.java:552)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:621)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:728)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:305)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210)
at org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:243)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:222)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:123)
at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:502)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:171)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:100)
at org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:953)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:118)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:409)
at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1044)
at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:607)
at org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:315)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1110)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:603)
at java.lang.Thread.run(Thread.java:722)

Mar 25, 2014 9:52:46 PM org.apache.catalina.core.StandardWrapperValve invoke
SEVERE: Servlet.service() for servlet [apple] in context with path [/ApplewithDate] threw exception [org.springframework.beans.NotReadablePropertyException: Invalid property 'Address_Id' of bean class [net.apple.domain.Address]: Bean property 'Address_Id' is not readable or has an invalid getter method: Does the return type of the getter match the parameter type of the setter?] with root cause
org.springframework.beans.NotReadablePropertyException: Invalid property 'Address_Id' of bean class [net.apple.domain.Address]: Bean property 'Address_Id' is not readable or has an invalid getter method: Does the return type of the getter match the parameter type of the setter?
at org.springframework.beans.BeanWrapperImpl.getPropertyValue(BeanWrapperImpl.java:665)
at org.springframework.beans.BeanWrapperImpl.getPropertyValue(BeanWrapperImpl.java:657)
at org.springframework.web.servlet.tags.form.OptionWriter.doRenderFromCollection(OptionWriter.java:202)
at org.springframework.web.servlet.tags.form.OptionWriter.renderFromCollection(OptionWriter.java:180)
at org.springframework.web.servlet.tags.form.OptionWriter.writeOptions(OptionWriter.java:133)
at org.springframework.web.servlet.tags.form.OptionsTag.writeTagContent(OptionsTag.java:168)
at org.springframework.web.servlet.tags.form.AbstractFormTag.doStartTagInternal(AbstractFormTag.java:102)
at org.springframework.web.servlet.tags.RequestContextAwareTag.doStartTag(RequestContextAwareTag.java:79)
at org.apache.jsp.WEB_002dINF.jsp.addEditProject_jsp._jspx_meth_form_005foptions_005f0(addEditProject_jsp.java:353)
at org.apache.jsp.WEB_002dINF.jsp.addEditProject_jsp._jspService(addEditProject_jsp.java:202)
at org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:70)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:728)
at org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:432)
at org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:390)
at org.apache.jasper.servlet.JspServlet.service(JspServlet.java:334)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:728)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:305)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210)
at org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:243)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210)
at org.apache.catalina.core.ApplicationDispatcher.invoke(ApplicationDispatcher.java:749)
at org.apache.catalina.core.ApplicationDispatcher.processRequest(ApplicationDispatcher.java:487)
at org.apache.catalina.core.ApplicationDispatcher.doForward(ApplicationDispatcher.java:412)
at org.apache.catalina.core.ApplicationDispatcher.forward(ApplicationDispatcher.java:339)
at org.springframework.web.servlet.view.InternalResourceView.renderMergedOutputModel(InternalResourceView.java:238)
at org.springframework.web.servlet.view.AbstractView.render(AbstractView.java:250)
at org.springframework.web.servlet.DispatcherServlet.render(DispatcherServlet.java:1060)
at org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:798)
at org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:716)
at org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:647)
at org.springframework.web.servlet.FrameworkServlet.doGet(FrameworkServlet.java:552)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:621)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:728)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:305)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210)
at org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:243)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:222)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:123)
at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:502)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:171)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:100)
at org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:953)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:118)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:409)
at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1044)
at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:607)
at org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:315)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1110)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:603)
at java.lang.Thread.run(Thread.java:722)


Please help .
 
Jayesh A Lalwani
Rancher
Posts: 2759
32
Eclipse IDE Spring Tomcat Server
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Nikhy,

The answer is right there in the exception that you posted. You are very close to the answer yourself. You just need to look at what the exception says, and process it. Does Address Bean have a property named Address_Id? Remember that in Javabeans convention, it should have a method named setAddress_Id and getAddress_Id

I don't know how new you are to Java programming in general. In Java, stack traces give you incredible amount of information. If you look at the closely, you can find out a lot of things
 
Nikhy Pai
Greenhorn
Posts: 13
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,

Thank you so much. The erroe is due to the fact that I used Address_Id instead of address_id . I have corrected it and now i am getting my list populated.

This is the code i added in addEditProject.jsp.

<label>Address Id:</label><form:select path="address_id" onchange="submitForm()">
<form:option value="0" >Select </form:option>
<form:options items="${listaddress}" itemLabel="address_desc" itemValue="address_id"/>
</form:select>
Thanking you once again
 
WHAT is your favorite color? Blue, no yellow, ahhhhhhh! Tiny ad:
Building a Better World in your Backyard by Paul Wheaton and Shawn Klassen-Koop
https://coderanch.com/wiki/718759/books/Building-World-Backyard-Paul-Wheaton
reply
    Bookmark Topic Watch Topic
  • New Topic