Cy_橘子
2019-03-02 11:11timer定时器报空指针异常为什么?
今天想到用timer写一个定时清空session值得定时器,但报空指针。
代码如下:
public void removeYZM( HttpServletRequest request, String code) {
Timer timer = new Timer();
System.out.println("验证码:------"+request.getSession().getAttribute(code));
timer.schedule(new TimerTask() {
public void run() {
// 删除session中存的验证码
request.getSession().removeAttribute(code);
timer.cancel();
}
}, 1 * 60 * 1000);
}
报错信息
Exception in thread "Timer-1" java.lang.NullPointerException
at com.temp.ssm.controller.UserClientController$1.run(UserClientController.java:51)
at java.util.TimerThread.mainLoop(Timer.java:555)
at java.util.TimerThread.run(Timer.java:505)
- 点赞
- 回答
- 收藏
- 复制链接分享
1条回答
为你推荐
- 【淡入淡出型菜单】为什么执行不了?
- html5
- javascript
- css
- chrome
- 1个回答
- 为什么设置透明度的功能并没有实现?
- html5
- javascript
- css
- chrome
- 2个回答
- 为什么这个导航栏左右摇摆?
- html5
- javascript
- css
- chrome
- 1个回答
- 获取定时器timer
- dao
- 0个回答
- 用户可自定义向自己发送消息的时间,自定义定时器问题
- 自定义定时器
- spring
- java
- timer
- 5个回答
换一换