当前位置:编程学习 > JAVA >>

空指针异常求解

public void login(){
try{
System.out.println("这个是id:"+loginFrame.getUserId());
            System.out.println("这个是pwd:"+loginFrame.getUserPwd());
int id=loginFrame.getUserId();
String pwd=loginFrame.getUserPwd();
User user=examService.login(id,pwd);
loginFrame.setVisible(false);
    menuFrame.updateView(user);
    menuFrame.setVisible(true);
}catch(NumberFormatException e){
e.printStackTrace();
loginFrame.showError("用户编号必须是数字");
}catch(IdOrPwdException e){
e.printStackTrace();
loginFrame.showError(e.getMessage());
}
}
public User login(int id,String pwd)throws IdOrPwdException{
User user=entityContext.findUserById(id);
if(user==null){
throw new IdOrPwdException("没有此用户");
}
if(!user.getPassword().equals(pwd)){
throw new IdOrPwdException("密码搞错了");
}
loginUser=user;
return user;
}
这个是报出的异常;
Exception in thread "AWT-EventQueue-0" java.lang.NullPointerException
at com.tarena.elts.service.ClientContext.login(ClientContext.java:31)
at com.tarena.elts.ui.LoginFrame$1.actionPerformed(LoginFrame.java:93)
at javax.swing.AbstractButton.fireActionPerformed(AbstractButton.java:1995)
at javax.swing.AbstractButton$Handler.actionPerformed(AbstractButton.java:2318)
at javax.swing.DefaultButtonModel.fireActionPerformed(DefaultButtonModel.java:387)这个是id:1001
这个是pwd:1234

at javax.swing.DefaultButtonModel.setPressed(DefaultButtonModel.java:242)
at javax.swing.plaf.basic.BasicButtonListener.mouseReleased(BasicButtonListener.java:236)
at java.awt.Component.processMouseEvent(Component.java:6216)
at javax.swing.JComponent.processMouseEvent(JComponent.java:3265)
at java.awt.Component.processEvent(Component.java:5981)
at java.awt.Container.processEvent(Container.java:2041)
at java.awt.Component.dispatchEventImpl(Component.java:4583)
at java.awt.Container.dispatchEventImpl(Container.java:2099)
at java.awt.Component.dispatchEvent(Component.java:4413)
at java.awt.LightweightDispatcher.retargetMouseEvent(Container.java:4556)
at java.awt.LightweightDispatcher.processMouseEvent(Container.java:4220)
at java.awt.LightweightDispatcher.dispatchEvent(Container.java:4150)
at java.awt.Container.dispatchEventImpl(Container.java:2085)
at java.awt.Window.dispatchEventImpl(Window.java:2475)
at java.awt.Component.dispatchEvent(Component.java:4413)
at java.awt.EventQueue.dispatchEvent(EventQueue.java:599)
at java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:269)
at java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:184)
at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:174)
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:169)
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:161)
at java.awt.EventDispatchThread.run(EventDispatchThread.java:122)

 这个实参值不是已经传入了吗


--------------------编程问答-------------------- 这种情况一般就是你的值没获取得,形成null引用就会有这个异常的
你好好查检一下,可以在发生异常的位置前加入输出语句来确认是不是真的是null
补充:Java ,  Java SE
CopyRight © 2022 站长资源库 编程知识问答 zzzyk.com All Rights Reserved
部分文章来自网络,