java.lang.reflect.InvocationTargetException

java.lang.reflect.InvocationTargetException
	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
	at java.lang.reflect.Method.invoke(Method.java:498)
	at cn.itcast.travel.web.servlet.baseServlet.service(baseServlet.java:28)
	at javax.servlet.http.HttpServlet.service(HttpServlet.java:728)
	at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:305)
	at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210)
	at cn.itcast.travel.web.filter.CharchaterFilter.doFilter(CharchaterFilter.java:32)
	at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:243)
	at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210)
	at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:222)
	at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:123)
	at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:472)
	at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:171)
	at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:99)
	at org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:936)
	at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:118)
	at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:407)
	at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1004)
	at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:589)
	at org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:312)
	at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
	at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
	at java.lang.Thread.run(Thread.java:748)
Caused by: java.lang.NullPointerException
	at cn.itcast.travel.web.servlet.categoryServlet.findByPage(categoryServlet.java:43)
	... 25 more

这不是第一次出现这个错误了,第一次解决这个错误的过程是

List<Category> category = travelCategory.findCategory();

这个代码是正确的原来错误的是

Category category = travelCategory.findCategory();

因为查询数据库返回的是一个list列表,而用实体类对象来装返回值明显不对

第二次

原因是service层写得有问题当查询不到结果时返回null

public pageBean<Route> findLimit(int currentPage, int rows, String cid) {
        int totalCounts = travelCategoryDao.findTotalCounts(Integer.parseInt(cid));
        if (totalCounts > 0) {
            int start = (currentPage - 1) * 5;
            List<Route> limit = travelCategoryDao.findLimit(start, rows, Integer.parseInt(cid));
            pageBean<Route> p1 = new pageBean<>();
            p1.setCurrentPage(currentPage);
            p1.setRows(rows);
            p1.setTotalCounts(totalCounts);
            int totalPage = totalCounts % rows == 0 ? totalCounts / rows : (totalCounts / rows) + 1;
            p1.setTotalPage(totalPage);
            p1.setList(limit);
            System.out.println("categoryImpl"+p1.toString());
            return p1;
        } else {
            System.out.println("categoryImpl :null");
            return null;
        }

System.out.println(“categoryImpl :null”);
return null;

pageBean p1 = travelCategory.findLimit(currentPage, rows, cid);
            System.out.println("categoryServlet:" + p1.toString());

            writeValue(p1, response);

而在使用java转换json工具类时很明显有错误

  • 0
    点赞
  • 0
    评论
  • 0
    收藏
  • 一键三连
    一键三连
  • 扫一扫,分享海报

相关推荐
©️2020 CSDN 皮肤主题: 数字20 设计师:CSDN官方博客 返回首页
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、C币套餐、付费专栏及课程。

余额充值