aspose file tools*
The moose likes JDBC and the fly likes Problem with null pointer exception in dao layer Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Soft Skills this week in the Jobs Discussion forum!
JavaRanch » Java Forums » Databases » JDBC
Bookmark "Problem with null pointer exception in dao layer" Watch "Problem with null pointer exception in dao layer" New topic
Author

Problem with null pointer exception in dao layer

shiva valanukonda
Greenhorn

Joined: Sep 27, 2010
Posts: 25

Hi,
Here is the sample code which is called by some service (myservice)
in Dao class:


in my Action Class:

displaying error msg;

Here, when i call this methos it throwing some null pointer exception. So, complete code is not executing . So, please help me out from this issue.

Thanks & regards
Shiva


Jan Cumps
Bartender

Joined: Dec 20, 2006
Posts: 2516
    
  10

Shiva,

can you post the exact error message, and at which line in your code it is thrown?

Also, when posting code, please use the Code button to format it. I have changed the post for you to format the code.


OCUP UML fundamental and ITIL foundation
youtube channel
T. Huy Nguyen
Ranch Hand

Joined: Nov 02, 2010
Posts: 57
Hi,

Your factory, qry, list and list.get(0) may be null and causing NullPointerException. Have you checked each of them?

If you have a proper exception stack trace or error message, identifying the cause will be much faster.


My material for SCJP (2008), SCWCD (2010), SCBCD (2010). About me
R. Grimes
Ranch Hand

Joined: Aug 23, 2009
Posts: 42
I would change your DAO line from



to



First, you made the mistake of using list.size instead of list.size(). Since the property "size" does not exist, it will throw an error. Only the method size() exists. Second, you should make sure there is something in the list before checking value within it. Thus, I switched your if statement.

Ron
 
 
subject: Problem with null pointer exception in dao layer