HTTP Status 500 - Request processing failed; nested exception is java.lang.NullPointerException
微wx笑 2020-04-12【编程语言】 8 0关键字: HTTP Java
HTTP Status 500 - Request processing failed; nested exception is java.lang.NullPointerExceptiontype Exception reportmessage Request processing failed; nested ex
HTTP Status 500 - Request processing failed; nested exception is java.lang.NullPointerException
type Exception report
message Request processing failed; nested exception is java.lang.NullPointerException
description The server encountered an internal error that prevented it from fulfilling this request.
exception
org.springframework.web.util.NestedServletException: Request processing failed; nested exception is java.lang.NullPointerException
org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:965)
org.springframework.web.servlet.FrameworkServlet.doGet(FrameworkServlet.java:844)
javax.servlet.http.HttpServlet.service(HttpServlet.java:620)
org.springframework.web.servlet.FrameworkServlet.service(FrameworkServlet.java:829)
javax.servlet.http.HttpServlet.service(HttpServlet.java:727)
org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)
com.auth.filter.AuthorizationFilter.doFilterInternal(AuthorizationFilter.java:77)
org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:106)
org.springframework.web.filter.DelegatingFilterProxy.invokeDelegate(DelegatingFilterProxy.java:343)
org.springframework.web.filter.DelegatingFilterProxy.doFilter(DelegatingFilterProxy.java:260)
com.auth.filter.AuthenticationFilter.doFilterInternal(AuthenticationFilter.java:111)
org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:106)
org.springframework.web.filter.DelegatingFilterProxy.invokeDelegate(DelegatingFilterProxy.java:343)
org.springframework.web.filter.DelegatingFilterProxy.doFilter(DelegatingFilterProxy.java:260)
org.springframework.web.filter.CharacterEncodingFilter.doFilterInternal(CharacterEncodingFilter.java:88)
org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:106)
root cause
java.lang.NullPointerException
com.xinghe.base.action.NoticePublic.listNotice(NoticePublic.java:44)
sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
java.lang.reflect.Method.invoke(Unknown Source)
org.springframework.web.bind.annotation.support.HandlerMethodInvoker.invokeHandlerMethod(HandlerMethodInvoker.java:176)
org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerAdapter.invokeHandlerMethod(AnnotationMethodHandlerAdapter.java:440)
org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerAdapter.handle(AnnotationMethodHandlerAdapter.java:428)
org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:919)
org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:851)
org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:953)
org.springframework.web.servlet.FrameworkServlet.doGet(FrameworkServlet.java:844)
javax.servlet.http.HttpServlet.service(HttpServlet.java:620)
org.springframework.web.servlet.FrameworkServlet.service(FrameworkServlet.java:829)
javax.servlet.http.HttpServlet.service(HttpServlet.java:727)
org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)
com.auth.filter.AuthorizationFilter.doFilterInternal(AuthorizationFilter.java:77)
org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:106)
org.springframework.web.filter.DelegatingFilterProxy.invokeDelegate(DelegatingFilterProxy.java:343)
org.springframework.web.filter.DelegatingFilterProxy.doFilter(DelegatingFilterProxy.java:260)
com.auth.filter.AuthenticationFilter.doFilterInternal(AuthenticationFilter.java:111)
org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:106)
org.springframework.web.filter.DelegatingFilterProxy.invokeDelegate(DelegatingFilterProxy.java:343)
org.springframework.web.filter.DelegatingFilterProxy.doFilter(DelegatingFilterProxy.java:260)
org.springframework.web.filter.CharacterEncodingFilter.doFilterInternal(CharacterEncodingFilter.java:88)
org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:106)
note The full stack trace of the root cause is available in the Apache Tomcat/7.0.54 logs.
Apache Tomcat/7.0.54
NullPointerException,这个错误很明显,就是没有对变量进行Null判断;
错误位置:com.xinghe.base.action.NoticePublic.listNotice(NoticePublic.java:44)
2019-04-22 更新
时隔四五年,但还是有必要更新一下。
java.lang.NullPointerException 这是 java 编程路上一个可能是最常遇到,也是最基本的一个问题。
对于初学者(小白)来说,看到这么长长的一大片错误信息,头一下子就大了,我当初也是。
那么这个问题怎么解决呢?
通常 java.lang.NullPointerException 后面会紧跟着出错的代码,这通常是你自己写的代码:
com.xinghe.base.action.NoticePublic.listNotice(NoticePublic.java:44)
看看括号中的文件名,是不是觉得很熟悉?
打开这个文件,本文中对应的是:NoticePublic.java,
再找到文件名后面提示的 44 行,
看看是不是很亲切!
比如我这里的一个可能出现 异常的代码:
IUser personal = SecurityUtils.getUser(request); Long personalId = personal.getId();
对象或者说变量“personal”是通过一个方法获取或者说赋值的,它可能是一个 Null 值,
一个 Null 值怎么会有getId()这个方法呢?
所以当“personal”为 Null 值的时候,你不做判断,就去调用 personal.getId(); 就会产生 java.lang.NullPointerException 异常,而解决方法就是添加一个判断:
IUser personal = SecurityUtils.getUser(request); if (null != personal){ Long personalId = personal.getId(); }
唠叨了这么多,你明白了没有呢?去寻找属于你的“personal”变量吧!
你的编辑器没有显示行号?
下面是Mac下的Eclipse设置方法:
既然你能搜索到这篇文章,那么我相信你是会用搜索引擎的;
去搜索:你的编程工具名称 如何显示行号 应该就可以找到答案了
本文由 微wx笑 创作,采用 署名-非商业性使用-相同方式共享 4.0 许可协议,转载请附上原文出处链接及本声明。
原文链接:https://www.ivu4e.cn/blog/lang/2020-04-12/392.html