File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes JDBC and Relational Databases 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
JavaRanch » Java Forums » Databases » JDBC and Relational Databases
Bookmark "Problem with null pointer exception in dao layer" Watch "Problem with null pointer exception in dao layer" New topic

Problem with null pointer exception in dao layer

shiva valanukonda

Joined: Sep 27, 2010
Posts: 26

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

Jan Cumps

Joined: Dec 20, 2006
Posts: 2565


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
T. Huy Nguyen
Ranch Hand

Joined: Nov 02, 2010
Posts: 57

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


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.

I agree. Here's the link:
subject: Problem with null pointer exception in dao layer
It's not a secret anymore!