File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Java in General and the fly likes NullPointerException Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Java in General
Bookmark "NullPointerException" Watch "NullPointerException" New topic
Author

NullPointerException

Adam Confino
Ranch Hand

Joined: Sep 03, 2009
Posts: 48
Hey Java Gurus!

I've posted my error message below and I believe line 14 in the code below is what is cited as the culprit.

HTTP ERROR 500 Problem accessing /bedbreakfast-webapp/searchresults.html. Reason:INTERNAL_SERVER_ERROR
Caused by:java.lang.NullPointerException

What are your thoughts on what the problem is?
Thanks so much. This forum is one of my best resources.



p.s. I thought it may be helpful for you to have the code to ReservationService.equalsDateRange(checkIn, checkOut)



Just Another Guy Hooked on Java
Tobi Sasse
Greenhorn

Joined: Sep 09, 2009
Posts: 10
I can't imagine that the Exception is directly related to the sourcecode you posted.

You should provide us with a complete stacktrace of the exception, which could help to find the problem.
Sebastian Janisch
Ranch Hand

Joined: Feb 23, 2009
Posts: 1183
List<Suite> suiteList = SuiteService.getSuiteList();


Are you sure that this does not return null ?


JDBCSupport - An easy to use, light-weight JDBC framework -
Rob Spoor
Sheriff

Joined: Oct 27, 2005
Posts: 19718
    
  20

Check out your server (Tomcat?) logs. They should contain the full stack trace.


SCJP 1.4 - SCJP 6 - SCWCD 5 - OCEEJBD 6
How To Ask Questions How To Answer Questions
Adam Confino
Ranch Hand

Joined: Sep 03, 2009
Posts: 48
It sounds like I need a better understanding of error logs. Here is my log from my server.

What information on this log would help me diagnose the problem? If that question requires too long of an answer, is there an article I could read on it.

Thanks so much

[INFO] Started Jetty Server
SuiteController.search() begin...
SuiteController.searchResults() begin...
2009-09-10 07:44:24.700::WARN: /bedbreakfast-webapp/searchresults.html
java.lang.NullPointerException
at com.jadcon.bedbreakfast.web.SuiteController.searchResults(SuiteController.java:58)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:585)
at org.springframework.web.bind.annotation.support.HandlerMethodInvoker.doInvokeMethod(HandlerMethodInvoker.java:421)
at org.springframework.web.bind.annotation.support.HandlerMethodInvoker.invokeHandlerMethod(HandlerMethodInvoker.java:136)
at org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerAdapter.invokeHandlerMethod(AnnotationMethodHandlerAdapter.java:326)
at org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerAdapter.handle(AnnotationMethodHandlerAdapter.java:313)
at org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:875)
at org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:807)
at org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:571)
at org.springframework.web.servlet.FrameworkServlet.doPost(FrameworkServlet.java:511)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:727)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:820)
at org.mortbay.jetty.servlet.ServletHolder.handle(ServletHolder.java:502)
at org.mortbay.jetty.servlet.ServletHandler.handle(ServletHandler.java:389)
at org.mortbay.jetty.security.SecurityHandler.handle(SecurityHandler.java:216)
at org.mortbay.jetty.servlet.SessionHandler.handle(SessionHandler.java:181)
at org.mortbay.jetty.handler.ContextHandler.handle(ContextHandler.java:765)
at org.mortbay.jetty.webapp.WebAppContext.handle(WebAppContext.java:417)
at org.mortbay.jetty.handler.ContextHandlerCollection.handle(ContextHandlerCollection.java:230)
at org.mortbay.jetty.handler.HandlerCollection.handle(HandlerCollection.java:114)
at org.mortbay.jetty.handler.HandlerWrapper.handle(HandlerWrapper.java:152)
at org.mortbay.jetty.Server.handle(Server.java:326)
at org.mortbay.jetty.HttpConnection.handleRequest(HttpConnection.java:534)
at org.mortbay.jetty.HttpConnection$RequestHandler.content(HttpConnection.java:879)
at org.mortbay.jetty.HttpParser.parseNext(HttpParser.java:747)
at org.mortbay.jetty.HttpParser.parseAvailable(HttpParser.java:218)
at org.mortbay.jetty.HttpConnection.handle(HttpConnection.java:404)
at org.mortbay.io.nio.SelectChannelEndPoint.run(SelectChannelEndPoint.java:409)
at org.mortbay.thread.QueuedThreadPool$PoolThread.run(QueuedThreadPool.java:520)


Henry Wong
author
Sheriff

Joined: Sep 28, 2004
Posts: 18896
    
  40

at com.jadcon.bedbreakfast.web.SuiteController.searchResults(SuiteController.java:58)


The NPE is happening in the searchResults() method, as you suspected. To get the exact line, you need to show us what line 58 of the SuiteController.java file is.

Henry


Books: Java Threads, 3rd Edition, Jini in a Nutshell, and Java Gems (contributor)
Adam Confino
Ranch Hand

Joined: Sep 03, 2009
Posts: 48
Henry

Line 58 is line 14 in the code below. I also posted the entire method ReservationService.equalsDateRange() earlier in the post. I'll be glad to post anything else that is needed - I just wanted to keep the thread readable.

Thanks.

Henry Wong
author
Sheriff

Joined: Sep 28, 2004
Posts: 18896
    
  40

Line 58 is line 14 in the code below. I also posted the entire method ReservationService.equalsDateRange() earlier in the post. I'll be glad to post anything else that is needed - I just wanted to keep the thread readable.


First, depending on the editor that you are using, you may be off by one or two lines -- so also check the lines before and after the line that you think it is.

Second, the stacktrace doesn't show equalsDateRange() on the stack, so you know that the method didn't happen in that method.


As for how to find it... you can either...

1. use a debugger and step through this.

2. add a bunch of "if" checks, to see if stuff is null when you get to that section of code.

Personally, between the two options, option 2 is probably easier... as option 1 may require that you write a small repeatable test case.

Henry
Rob Spoor
Sheriff

Joined: Oct 27, 2005
Posts: 19718
    
  20

Are you sure it's not line 13: for (Suite suite : suiteList) ?
Because I think Sebastian was right:
Sebastian Janisch wrote:
List<Suite> suiteList = SuiteService.getSuiteList();


Are you sure that this does not return null ?
Adam Confino
Ranch Hand

Joined: Sep 03, 2009
Posts: 48
I did find the error. This code was part of a controller and the controller annotations were off.

Thanks so much for your help.

Adam
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: NullPointerException