求助~空指针问题
程序代码:
package com.zky.www.view; import java.awt.*; import javax.swing.*; import com.zky.www.bean.User; import com.zky.www.dao.Dao; import java.awt.event.*; public class UpdatePassIFrame extends JInternalFrame{ private JLabel lbusername=new JLabel("用户名:"); private JTextField txtusername=new JTextField(); private JLabel lboldpassword=new JLabel("旧密码:"); private JPasswordField txtoldpassword=new JPasswordField(); private JLabel lbnewpassword=new JLabel("新密码:"); private JPasswordField txtnewpassword=new JPasswordField(); private JLabel lbnewpassword2=new JLabel("确认密码:"); private JPasswordField txtnewpassword2=new JPasswordField(); private JButton btnupdate=new JButton("修改"); private JButton btnreset=new JButton("重置"); User user=LoginFrame.getUser(); //新建User对象 UpdatePassIFrame() { this.setSize(new Dimension(320,300)); this.setLocation(240, 120); this.setClosable(true); //设置窗口可以关闭 this.setMaximizable(false); //设置子窗体不允许最大化 this.setIconifiable(true); //设置子窗体可以图标化 this.setTitle("修改密码"); lbusername.setBounds(50, 40, 60, 25); txtusername.setBounds(120, 40, 140,25); txtusername.setText(user.getUsername()); //将当前登录用户名放入用户名文本框中 txtusername.setEditable(false); //设置使调用这个方法的控件不允许被编辑 lboldpassword.setBounds(50, 75, 60, 25); txtoldpassword.setBounds(120, 75, 140, 25); lbnewpassword.setBounds(50, 110, 60, 25); txtnewpassword.setBounds(120, 110, 140, 25); lbnewpassword2.setBounds(50, 145, 60, 25); txtnewpassword2.setBounds(120, 145, 140, 25); btnupdate.setBounds(80, 200, 60, 25); btnreset.setBounds(150, 200, 60, 25); Container cont=this.getContentPane(); cont.setLayout(null); cont.add(lbusername); cont.add(txtusername); cont.add(lboldpassword); cont.add(txtoldpassword); cont.add(lbnewpassword); cont.add(txtnewpassword); cont.add(lbnewpassword2); cont.add(txtnewpassword2); cont.add(btnupdate); cont.add(btnreset); btnupdate.addActionListener(new UpdatePasswordAction()); //将修改按钮加入监听事件 this.setVisible(true); } private class UpdatePasswordAction implements ActionListener { @Override public void actionPerformed(ActionEvent e) { String username=user.getUsername(); //用户名是从数据库获取的当前User名字 String oldpassword=txtoldpassword.getText().trim(); //旧密码为用户输入 String newpassword=txtnewpassword.getText().trim(); String newpassword2=txtnewpassword2.getText().trim(); if(null!=oldpassword &&!"".equals(oldpassword)) { if(oldpassword.equals(user.getPassword())){ if(null!=newpassword&&!"".equals(newpassword)&&newpassword.equals(newpassword2)) { int flag=Dao.updatePassword(username,newpassword); if(flag>0) { JOptionPane.showMessageDialog(null, "密码修改成功!"); user.setPassword(newpassword); }else{ JOptionPane.showMessageDialog(null, "密码修改失败!"); } } else{ JOptionPane.showMessageDialog(null, "两次密码不一致或密码为空!"); txtnewpassword.setText(""); txtnewpassword2.setText(""); txtnewpassword.requestFocus(); } }else{ JOptionPane.showMessageDialog(null, "旧密码不正确!"); txtoldpassword.setText(""); txtoldpassword.requestFocus(); } }else { JOptionPane.showMessageDialog(null, "旧密码不能为空!"); txtoldpassword.setText(""); txtoldpassword.requestFocus(); } } } }
这是一个小的修改密码的程序,数据库我才用的是mycycle,如上面代码以及异常图片所示,在修改的时候遇到了空指针问题,即使User对象的问题,但是不知道咋解决,求大神帮忙,多谢!