日期:2014-05-19  浏览次数:20722 次

奇怪的空指针异常!急!
本帖最后由 xcfdsarfew 于 2013-01-03 02:24:41 编辑

/**@see {@link TopicDao#getTopicList(int, int, int, int)}*/
@Override
public Page<BBSTopic> getTopicList(int topicid, int pageNum, int pageSize,
int size) throws Exception {

String hql = " select new BBSTopic(id,uName,topicTitle,allView," +
"allReplay,isHaveImage,isHaveVideo,createTime," +
"isBirght,birghtEndTime,birghtColor,isTop," +
"topEndTime,isSoul,soulEndTime,lastModifyTime,htmlPath) " +
"from BBSTopic a where EXISTS " +
"(select 'x' from BBSEdition c where " +
"SUBSTR(edtionString,(select GROUP_CONCAT(d.edtionStart,',',d.edtionEnd) " +
"from BBSEdition d where d.id=:id))=:editId and c.id=a.editionid) and a.topicStatus=:topicStatus ";

Map<String, Object> parmap = new HashMap<String, Object>();
parmap.put("id", topicid);
parmap.put("editId", topicid);
parmap.put("topicStatus",BBSTopic.STATUS_已审核);
return baseDao.findPageReList(hql, parmap, true, size, pageSize,
pageNum);
}


这里我用的是泛型dao 脚本应该没错  但是在createQuery的时候就抛出了空指针异常
而且其他没任何提示
where条件里面的问题但是这SQL我直接运行又没问题!求解释

------解决方案--------------------
异常贴出来看看
------解决方案--------------------

at com.onionportal.until.dao.imp.BaseDAOImpl$7.doInHibernate(BaseDAOImpl.java:182)
    at org.springframework.orm.hibernate3.HibernateTemplate.doExecute(HibernateTemplate.java:406)
    at org.springframework.orm.hibernate3.HibernateTemplate.execute(HibernateTemplate.java:339)
    at com.onionportal.until.dao.imp.BaseDAOImpl.findEntity(BaseDAOImpl.java:178)
    at com.onionportal.until.dao.imp.BaseDAOImpl.findPageReList(BaseDAOImpl.java:485)
    at com.onionportal.bbs.dao.imp.TopicDaoImp.getTopicList(TopicDaoImp.java:44)


建议LZ自己debug模式,去baseDAOImpl里面单步调试。
------解决方案--------------------
很多时候,在Java里出现这个异常是因为没有初始化,虽然语法上没错,但是在逻辑上,漏了一个语句