现在用的框架是ssh的,但是我用自动生成的dao里面的方法的时候总是报java.lang.NullPointerException这个异常我仔细检查了好久大家帮我看看吧,多谢了<*---------------------------------------------------------------------*>package struts.report.action;import dao.account.impl.AccountDAO;
import struts.base.BaseAction;
public class Consumption extends BaseAction{
private int[] overdraftNo = new int[10];
private AccountDAO accountDAO = new AccountDAO();
public String consumeReport(){

for(int i=1;i<=10;i++){
overdraftNo[i]=accountDAO.findByAccountNo("abc1234560").size();
System.out.println(overdraftNo[i]);
}
return SUCCESS;
}
}
<*-----------------------------------------------------------------*>这是AccountDAO里面的两个方法,自动生成的。。 public List findByProperty(String propertyName, Object value) {
log.debug("finding Account instance with property: " + propertyName
+ ", value: " + value);
try {
String queryString = "from Account as model where model."
+ propertyName + "= ?";
return getHibernateTemplate().find(queryString, value);
} catch (RuntimeException re) {
log.error("find by property name failed", re);
throw re;
}
} /* (non-Javadoc)
 * @see dao.account.impl.IAccountDAO#findByAccountNo(java.lang.Object)
 */
public List findByAccountNo(Object accountNo) {
return findByProperty(ACCOUNT_NO, accountNo);
}<*-------------------------------------------------------------------------*>
出错的是at dao.account.impl.AccountDAO.findByProperty(AccountDAO.java:128)
at dao.account.impl.AccountDAO.findByAccountNo(AccountDAO.java:139)
两个return的地方。 我仔细看了数据库,没问题。。

解决方案 »

  1.   

    可能是spring配置文件中AccountDAO没有配置HibernateTemplate这个属性
      

  2.   

    你用SSH架构,但我怎么在ACTION里面没看到你有把AccountDAO set进去,而是 new 一下 ???
      

  3.   

    private AccountDAO accountDAO = new AccountDAO(); 这句出问题了。
    在ssh中所有的类,都要由spring容器生成
      

  4.   

    你的spring配置文件没有把sessionFactory注入进去AccountDAO吧?