java.lang.NullPointerException

There are no available Samebug tips for this exception. Do you have an idea how to solve this issue? A short tip would help users who saw this issue last week.

  • I am playing with the JdbcTemplate and have the following code: JdbcTemplate jdbc = new JdbcTemplate(); String[] s = (String[]) jdbc.queryForObject(SELECT_SQL, new Object[]{new Long(id)}, java.lang.String[].class); As I do not pass in a datasource to JdbcTemplate and does not call setDataSource on it I get the following NPE. Maybe a check in the code and to throw a propper exception stating somekind of error text that a datasource is not set on the template would be nice instead of a NPE. Just to add to Jurgens/Thomas list of silly TODO's instead of cool new features. java.lang.NullPointerException at org.springframework.jdbc.datasource.DataSourceUtils.doGetConnection(DataSourceUtils.java:173) at org.springframework.jdbc.datasource.DataSourceUtils.getConnection(DataSourceUtils.java:152) at org.springframework.jdbc.datasource.DataSourceUtils.getConnection(DataSourceUtils.java:128) at org.springframework.jdbc.core.JdbcTemplate.execute(JdbcTemplate.java:319) at org.springframework.jdbc.core.JdbcTemplate.query(JdbcTemplate.java:374) at org.springframework.jdbc.core.JdbcTemplate.query(JdbcTemplate.java:410) at org.springframework.jdbc.core.JdbcTemplate.queryForObject(JdbcTemplate.java:469) at com.bmd.selfservice.dao.KundeHibernateDAO.loadKundeEmail(KundeHibernateDAO.java:55) at com.bmd.selfservice.KundeBusiness.getKundeEmail(KundeBusiness.java:40) at com.bmd.selfservice.demo.KundeDemo.email(KundeDemo.java:55) at com.bmd.selfservice.demo.KundeDemo.main(KundeDemo.java:62)
    via by Claus Ibsen,
  • I am playing with the JdbcTemplate and have the following code: JdbcTemplate jdbc = new JdbcTemplate(); String[] s = (String[]) jdbc.queryForObject(SELECT_SQL, new Object[]{new Long(id)}, java.lang.String[].class); As I do not pass in a datasource to JdbcTemplate and does not call setDataSource on it I get the following NPE. Maybe a check in the code and to throw a propper exception stating somekind of error text that a datasource is not set on the template would be nice instead of a NPE. Just to add to Jurgens/Thomas list of silly TODO's instead of cool new features. java.lang.NullPointerException at org.springframework.jdbc.datasource.DataSourceUtils.doGetConnection(DataSourceUtils.java:173) at org.springframework.jdbc.datasource.DataSourceUtils.getConnection(DataSourceUtils.java:152) at org.springframework.jdbc.datasource.DataSourceUtils.getConnection(DataSourceUtils.java:128) at org.springframework.jdbc.core.JdbcTemplate.execute(JdbcTemplate.java:319) at org.springframework.jdbc.core.JdbcTemplate.query(JdbcTemplate.java:374) at org.springframework.jdbc.core.JdbcTemplate.query(JdbcTemplate.java:410) at org.springframework.jdbc.core.JdbcTemplate.queryForObject(JdbcTemplate.java:469) at com.bmd.selfservice.dao.KundeHibernateDAO.loadKundeEmail(KundeHibernateDAO.java:55) at com.bmd.selfservice.KundeBusiness.getKundeEmail(KundeBusiness.java:40) at com.bmd.selfservice.demo.KundeDemo.email(KundeDemo.java:55) at com.bmd.selfservice.demo.KundeDemo.main(KundeDemo.java:62)
    via by Claus Ibsen,
    • java.lang.NullPointerException at org.springframework.jdbc.datasource.DataSourceUtils.doGetConnection(DataSourceUtils.java:173) at org.springframework.jdbc.datasource.DataSourceUtils.getConnection(DataSourceUtils.java:152) at org.springframework.jdbc.datasource.DataSourceUtils.getConnection(DataSourceUtils.java:128) at org.springframework.jdbc.core.JdbcTemplate.execute(JdbcTemplate.java:319) at org.springframework.jdbc.core.JdbcTemplate.query(JdbcTemplate.java:374) at org.springframework.jdbc.core.JdbcTemplate.query(JdbcTemplate.java:410) at org.springframework.jdbc.core.JdbcTemplate.queryForObject(JdbcTemplate.java:469) at com.bmd.selfservice.dao.KundeHibernateDAO.loadKundeEmail(KundeHibernateDAO.java:55) at com.bmd.selfservice.KundeBusiness.getKundeEmail(KundeBusiness.java:40) at com.bmd.selfservice.demo.KundeDemo.email(KundeDemo.java:55) at com.bmd.selfservice.demo.KundeDemo.main(KundeDemo.java:62)
    No Bugmate found.