Sunday, 8 September 2013

Spring 3 -- NullPointerException passing a List from a DAO to a custom tag

Spring 3 -- NullPointerException passing a List from a DAO to a custom tag

I have a custom tag in my Spring 3 application that is calling a DAO
class. The DAO class performs a call to my database, and I have verified
that call does return the List it's supposed to return. I'm trying to pass
that list back to my custom tag, but the call from the custom tag is
getting a NullPointerException instead of the list. When I try to print
out a message from the NullPointerException, that also gives me null. Can
anyone help me? Here is my tag.
public void doTag() throws JspException, IOException {
try {
List<Comment> commentList = commentDAO.getComments();
// do processing with the comment -- not part of the problem,
// since the thrown exception is currently preventing it
} catch (NullPointerException e) {
System.out.println(e.getMessage());
}
}
Here is the call to my database, which works correctly.
public List<Comment> getComments() {
try {
List<Comment> comments = this.getJdbcTemplate().query("select *
from comments",
new BeanPropertyRowMapper<Comment>(Comment.class));
return comments;
} catch (DataAccessException e) {
e.getMessage();
return null;
}
}

No comments:

Post a Comment