NutzCN Logo
问答 dao报空指针异常不知道什么原因
发布于 2076天前 作者 wx_2jk6i7mpius707s625cs 1541 次浏览 复制 上一个帖子 下一个帖子
标签:
package net.wendal.nutzbook.dao;
import java.util.ArrayList;
import java.util.List;
import org.apache.log4j.Logger;
import org.nutz.dao.Cnd;
import org.nutz.dao.Dao;
import org.nutz.ioc.loader.annotation.Inject;
import org.nutz.ioc.loader.annotation.IocBean;
import cn.hutool.json.JSONArray;
import cn.hutool.json.JSONObject;
import cn.hutool.json.JSONUtil;
import net.wendal.nutzbook.bean.VipCards;
import net.wendal.nutzbook.bean.VipDetailBean;
@IocBean
public class VipCardsDao extends UserDao{
	private static Logger logger = Logger.getLogger(VipCardsDao.class);
	@Inject
	Dao dao;
	JSONObject jsonObject = new JSONObject();
	public VipDetailBean getCardD(String CardNumber){
		//Cnd cnd =Cnd.where("CardNumber", "=",CardNumber);
		logger.info(CardNumber);
		VipDetailBean vipDetailBean = dao.fetch(VipDetailBean.class);
		/*		logger.info(vipDetailBean.toString());
		String code = vipDetailBean.getCardCode();
		Cnd cnd1 =Cnd.where("FAcctCode", "=",code);
		List<AcctsBean> list = dao.query(AcctsBean.class, cnd);
		vipDetailBean.setList(list);*/
		return vipDetailBean;
		
	}
java.lang.NullPointerException
	at net.wendal.nutzbook.dao.VipCardsDao.getCardD(VipCardsDao.java:43)
	at net.wendal.nutzbook.action.UserCardsAction.viewCard(UserCardsAction.java:52)
	at net.wendal.nutzbook.action.UserCardsAction$FM$viewCard$8ca68ff379736e775d8f0116d4dbb445.invoke(UserCardsAction.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:30)
	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.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.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:220)
	at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:122)
	at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:501)
	at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:170)
	at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:98)
	at org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:950)
	at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:116)
	at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:408)
	at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1040)
	at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:607)
	at org.apache.tomcat.util.net.AprEndpoint$SocketProcessor.doRun(AprEndpoint.java:2441)
	at org.apache.tomcat.util.net.AprEndpoint$SocketProcessor.run(AprEndpoint.java:2430)
	at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)
	at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
	at java.lang.Thread.run(Unknown Source)
4 回复

UserCardsAction里面是不是直接new VipCardsDao了?

package net.wendal.nutzbook.action;

import java.util.List;

import javax.servlet.http.HttpSession;

import org.apache.log4j.Logger;
import org.nutz.dao.Cnd;
import org.nutz.dao.Dao;
import org.nutz.dao.QueryResult;
import org.nutz.dao.pager.Pager;
import org.nutz.ioc.loader.annotation.Inject;
import org.nutz.ioc.loader.annotation.IocBean;
import org.nutz.lang.util.NutMap;
import org.nutz.mvc.annotation.At;
import org.nutz.mvc.annotation.Fail;
import org.nutz.mvc.annotation.Ok;
import org.nutz.mvc.annotation.Param;

import net.wendal.nutzbook.bean.VipCards;
import net.wendal.nutzbook.bean.VipDetailBean;
import net.wendal.nutzbook.dao.UserDao;
import net.wendal.nutzbook.dao.VipCardsDao;

@IocBean
@At("/cards")
@Ok(value = "json")
@Fail("http:500")
public class UserCardsAction {
	private static Logger logger = Logger.getLogger(UserCardsAction.class);
	@Inject
	VipCardsDao VipCardsDao;
	@Inject
	UserDao userDao;
	 @At
	 @Ok("json:full")
	 public Object query(HttpSession httpSession, @Param("..")Pager pager) {
	      //Cnd cnd = Strings.isBlank(name)? null : Cnd.where("name", "like", "%"+name+"%");
	      QueryResult qr = new QueryResult();
	      String Phone =httpSession.getAttribute("me").toString();
	      List<VipCards> cards = VipCardsDao.getCards(Phone);
	      qr.setList(cards);
	      pager.setRecordCount(cards.size());
	      qr.setPager(pager);
	      return qr; //默认分页是第1页,每页20条
	  }
	 @At
	 @Ok("json:full")
	 public Object viewCard(@Param("cardNumber")String cardNumber) {
		VipCardsDao vipCardsDao =new VipCardsDao();
		logger.info(cardNumber);
		VipDetailBean vipDetailBean =vipCardsDao.getCardD(cardNumber);
		 return new NutMap().setv("ok", true);
	 }
	
}

变量名不要大写开头, 容易自己挖坑

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