NutzCN Logo
问答 dao注入的问题,报错空指针
发布于 2543天前 作者 qq_2ac473ac 1550 次浏览 复制 上一个帖子 下一个帖子
标签:

始终报错空指针,但是另外一个地方却能用,问题出现在哪儿啊

@IocBean(fields="dao")
public class PartTimeService extends IdNameEntityService<PartTimer> {
	protected Dao dao;

public  int regist(PartTimer parttimer) {
	// TODO Auto-generated method stub
	int stae=0;
	System.err.println(parttimer.getUsername());
	System.out.println(parttimer.getUsername());
	 List partTimer2=(List) dao.fetch(user.class, "admin");
	if(partTimer2==null) {
		parttimer.setCreateTime(new Date());
		parttimer.setUpdateTime(new Date());
		PartTimer s=dao.insert(parttimer);		
		if(s.getId()!=0) {
			stae=1;
		}
	}
	return stae;
}
}



java.lang.NullPointerException
	at com.qcjy.kotya.service.PartTimeService.regist(PartTimeService.java:26)
	at com.qcjy.kotya.module.PartTimeModule.register(PartTimeModule.java:48)
	at com.qcjy.kotya.module.PartTimeModule$FM$register$93b618f5cb9e7cc4d39d15eed838d4a9.invoke(PartTimeModule.java)
	at org.nutz.mvc.impl.processor.MethodInvokeProcessor.process(MethodInvokeProcessor.java:31)
	at org.nutz.mvc.impl.processor.AbstractProcessor.doNext(AbstractProcessor.java:44)
	at org.nutz.mvc.impl.processor.AdaptorProcessor.process(AdaptorProcessor.java:33)
	at org.nutz.mvc.impl.processor.AbstractProcessor.doNext(AbstractProcessor.java:44)
	at org.nutz.mvc.impl.processor.ActionFiltersProcessor.process(ActionFiltersProcessor.java:58)
	at org.nutz.mvc.impl.processor.AbstractProcessor.doNext(AbstractProcessor.java:44)
	at org.nutz.integration.shiro.NutShiroProcessor.process(NutShiroProcessor.java:126)
	at org.nutz.mvc.impl.processor.AbstractProcessor.doNext(AbstractProcessor.java:44)
	at org.nutz.mvc.impl.processor.ModuleProcessor.process(ModuleProcessor.java:123)
	at org.nutz.mvc.impl.processor.AbstractProcessor.doNext(AbstractProcessor.java:44)
	at org.nutz.mvc.impl.processor.EncodingProcessor.process(EncodingProcessor.java:27)
	at org.nutz.mvc.impl.processor.AbstractProcessor.doNext(AbstractProcessor.java:44)
	at org.nutz.mvc.impl.processor.UpdateRequestAttributesProcessor.process(UpdateRequestAttributesProcessor.java:15)
	at org.nutz.mvc.impl.NutActionChain.doChain(NutActionChain.java:44)
	at org.nutz.mvc.impl.ActionInvoker.invoke(ActionInvoker.java:67)
	at org.nutz.mvc.ActionHandler.handle(ActionHandler.java:31)
	at org.nutz.mvc.NutFilter.doFilter(NutFilter.java:202)
	at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:241)
	at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:208)
	at org.apache.shiro.web.servlet.AbstractShiroFilter.executeChain(AbstractShiroFilter.java:449)
	at org.apache.shiro.web.servlet.AbstractShiroFilter$1.call(AbstractShiroFilter.java:365)
	at org.apache.shiro.subject.support.SubjectCallable.doCall(SubjectCallable.java:90)
	at org.apache.shiro.subject.support.SubjectCallable.call(SubjectCallable.java:83)
	at org.apache.shiro.subject.support.DelegatingSubject.execute(DelegatingSubject.java:383)
	at org.apache.shiro.web.servlet.AbstractShiroFilter.doFilterInternal(AbstractShiroFilter.java:362)
	at org.apache.shiro.web.servlet.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:125)
	at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:241)
	at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:208)
	at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:219)

5 回复

把dao属性删掉

protected Dao dao;

另外一个地方一样的,为啥生效的啊?

@IocBean(fields="dao")
public class ManuscriptService {
	protected Dao dao;
	public List<ManuscriptType> getConfigs(String types) {
	//	dao.fetch(ManuscriptType.class,Cnd.where("type", "=", type))
	
				List<ManuscriptType> mt=dao.query(ManuscriptType.class, Cnd.where("type", "=", types));
				return mt;
	}
	public Object  addManuscript(Manuscript manuscript) {
		manuscript.setReciverid(Toolkit.getloginid());
		manuscript.setCreateTime(new Date());
		manuscript.setUpdateTime(new Date());
		manuscript.setUpdater(Toolkit.getloginid());
		manuscript=dao.insert(manuscript);
		return manuscript;
	}

有属性dao和没有属性dao有啥区别啊

protected Dao dao;

IdNameEntityService已经有dao属性

哦,谢谢大神,没注意这个问题啊!

添加回复
请先登陆
回到顶部