反方向头发一幅图 2021-05-24 13:19 采纳率: 60%
浏览 63
已采纳

求大佬帮忙修改一下错误!!!!!!在这多谢各位大佬

 这是代码

package edu.cn.kluniv.sjz.sis.view;

import java.awt.BorderLayout;
import java.awt.EventQueue;

import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.border.EmptyBorder;

import edu.cn.kluniv.sjz.sis.dao.UserDao;
import edu.cn.kluniv.sjz.sis.model.User;
import edu.cn.kluniv.sjz.sis.util.StringUtil;

import javax.swing.GroupLayout;
import javax.swing.GroupLayout.Alignment;
import javax.swing.JLabel;
import javax.swing.JOptionPane;
import javax.swing.JTextField;
import javax.swing.JButton;
import javax.swing.LayoutStyle.ComponentPlacement;
import javax.swing.ImageIcon;
import java.awt.event.ActionListener;
import java.awt.event.ActionEvent;

public class ModifyPasswordView extends JFrame {

	private JPanel contentPane;
	//private JTextField textField;
	//private JTextField textField_1;
	//private JTextField textField_2;
	private JTextField oldPasswrdtextField;
	private JTextField newPasswrdtextField;
	private JTextField confirmPasswrdtextField;
	private User user;
	private UserDao userDao;
	private String account;
	
	
	
	private void confirmPasswordValue(ActionEvent evt) {
		// TODO Auto-generated method stub
		String oldPassword = oldPasswrdtextField.getText().toString();
		String newPassword = newPasswrdtextField.getText().toString();
		String confirmPassword = confirmPasswrdtextField.getText().toString();
		
		if(StringUtil.isEmpty(oldPassword)) {
			JOptionPane.showMessageDialog(this, "请填写旧密码");
		}else if(StringUtil.isEmpty(newPassword)) {
			JOptionPane.showMessageDialog(this, "请填写新密码");
		}else if(StringUtil.isEmpty(confirmPassword)) {
			JOptionPane.showMessageDialog(this, "请确认新密码");
		}else if(!(newPassword.equals(confirmPassword))) {
			JOptionPane.showMessageDialog(this, "两次密码输入不一致");
			resetValue();
			return;
		}else if(oldPassword.equals(newPassword)) {
			JOptionPane.showMessageDialog(this, "新旧密码一致,请重新输入");
			resetValue();
	}else {
		user = new User(account,newPassword);
		String retStr = userDao.updatePassword(user,account,oldPassword);
		JOptionPane.showMessageDialog(this,retStr);
		resetValue();
		if(retStr.equals("密码修改成功"))
			this.dispose();
	}
	}
	
	protected void resetValue(ActionEvent evt) {
		resetValue();
	}

	private void resetValue() {
		// TODO Auto-generated method stub
		oldPasswrdtextField.setText("");
		newPasswrdtextField.setText("");
		confirmPasswrdtextField.setText("");
	}
	

	/**
	 * Launch the application.
	 */
	public static void main(String[] args) {
		EventQueue.invokeLater(new Runnable() {
			public void run() {
				try {
					ModifyPasswordView frame = new ModifyPasswordView();
					frame.setVisible(true);
				} catch (Exception e) {
					e.printStackTrace();
				}
			}
		});
	}

	/**
	 * Create the frame.
	 */
	public ModifyPasswordView() {
		setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
		setBounds(100, 100, 450, 300);
		contentPane = new JPanel();
		contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
		setContentPane(contentPane);
		
		JLabel lblNewLabel = new JLabel("\u65E7\u5BC6\u7801");
		lblNewLabel.setIcon(new ImageIcon(ModifyPasswordView.class.getResource("/edu/cn/kluniv/sjz/sis/image/\u5BC6\u7801 .png")));
		
		JLabel lblNewLabel_1 = new JLabel("\u65B0\u5BC6\u7801");
		lblNewLabel_1.setIcon(new ImageIcon(ModifyPasswordView.class.getResource("/edu/cn/kluniv/sjz/sis/image/\u5BC6\u7801.png")));
		
		JLabel lblNewLabel_2 = new JLabel("\u786E\u8BA4\u5BC6\u7801");
		lblNewLabel_2.setIcon(new ImageIcon(ModifyPasswordView.class.getResource("/edu/cn/kluniv/sjz/sis/image/\u5BC6\u7801.png")));
		
		oldPasswrdtextField = new JTextField();
		oldPasswrdtextField.setColumns(10);
		
		newPasswrdtextField = new JTextField();
		newPasswrdtextField.setColumns(10);
		
		confirmPasswrdtextField = new JTextField();
		confirmPasswrdtextField.setColumns(10);
		
		JButton ConfirmButton = new JButton("\u786E\u8BA4");
		ConfirmButton.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent evt) {
				confirmPasswordValue(evt);
			}
		});
		ConfirmButton.setIcon(new ImageIcon(ModifyPasswordView.class.getResource("/edu/cn/kluniv/sjz/sis/image/\u786E\u8BA4.png")));
		
		JButton ResetButton = new JButton("\u91CD\u7F6E");
		ResetButton.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent evt) {
				resetValue(evt);
			}

			
		});
		ResetButton.setIcon(new ImageIcon(ModifyPasswordView.class.getResource("/edu/cn/kluniv/sjz/sis/image/\u91CD\u7F6E.png")));
		GroupLayout gl_contentPane = new GroupLayout(contentPane);
		gl_contentPane.setHorizontalGroup(
			gl_contentPane.createParallelGroup(Alignment.LEADING)
				.addGroup(gl_contentPane.createSequentialGroup()
					.addGap(53)
					.addGroup(gl_contentPane.createParallelGroup(Alignment.TRAILING)
						.addGroup(gl_contentPane.createSequentialGroup()
							.addGroup(gl_contentPane.createParallelGroup(Alignment.LEADING)
								.addComponent(lblNewLabel)
								.addComponent(lblNewLabel_1)
								.addComponent(lblNewLabel_2))
							.addGap(44))
						.addGroup(gl_contentPane.createSequentialGroup()
							.addComponent(ConfirmButton)
							.addGap(18)))
					.addGroup(gl_contentPane.createParallelGroup(Alignment.LEADING)
						.addComponent(confirmPasswrdtextField, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE)
						.addComponent(newPasswrdtextField, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE)
						.addComponent(oldPasswrdtextField, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE)
						.addComponent(ResetButton))
					.addContainerGap(131, Short.MAX_VALUE))
		);
		gl_contentPane.setVerticalGroup(
			gl_contentPane.createParallelGroup(Alignment.LEADING)
				.addGroup(gl_contentPane.createSequentialGroup()
					.addGap(39)
					.addGroup(gl_contentPane.createParallelGroup(Alignment.BASELINE)
						.addComponent(lblNewLabel)
						.addComponent(oldPasswrdtextField, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE))
					.addGap(18)
					.addGroup(gl_contentPane.createParallelGroup(Alignment.BASELINE)
						.addComponent(lblNewLabel_1)
						.addComponent(newPasswrdtextField, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE))
					.addGap(18)
					.addGroup(gl_contentPane.createParallelGroup(Alignment.BASELINE)
						.addComponent(lblNewLabel_2)
						.addComponent(confirmPasswrdtextField, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE))
					.addGap(18)
					.addGroup(gl_contentPane.createParallelGroup(Alignment.BASELINE)
						.addComponent(ResetButton)
						.addComponent(ConfirmButton))
					.addContainerGap(38, Short.MAX_VALUE))
		);
		contentPane.setLayout(gl_contentPane);
	}
}

报错如下

Exception in thread "AWT-EventQueue-0" java.lang.NullPointerException
	at edu.cn.kluniv.sjz.sis.view.ModifyPasswordView.confirmPasswordValue(ModifyPasswordView.java:61)
	at edu.cn.kluniv.sjz.sis.view.ModifyPasswordView.access$0(ModifyPasswordView.java:40)
	at edu.cn.kluniv.sjz.sis.view.ModifyPasswordView$2.actionPerformed(ModifyPasswordView.java:128)
	at javax.swing.AbstractButton.fireActionPerformed(Unknown Source)
	at javax.swing.AbstractButton$Handler.actionPerformed(Unknown Source)
	at javax.swing.DefaultButtonModel.fireActionPerformed(Unknown Source)
	at javax.swing.DefaultButtonModel.setPressed(Unknown Source)
	at javax.swing.plaf.basic.BasicButtonListener.mouseReleased(Unknown Source)
	at java.awt.Component.processMouseEvent(Unknown Source)
	at javax.swing.JComponent.processMouseEvent(Unknown Source)
	at java.awt.Component.processEvent(Unknown Source)
	at java.awt.Container.processEvent(Unknown Source)
	at java.awt.Component.dispatchEventImpl(Unknown Source)
	at java.awt.Container.dispatchEventImpl(Unknown Source)
	at java.awt.Component.dispatchEvent(Unknown Source)
	at java.awt.LightweightDispatcher.retargetMouseEvent(Unknown Source)
	at java.awt.LightweightDispatcher.processMouseEvent(Unknown Source)
	at java.awt.LightweightDispatcher.dispatchEvent(Unknown Source)
	at java.awt.Container.dispatchEventImpl(Unknown Source)
	at java.awt.Window.dispatchEventImpl(Unknown Source)
	at java.awt.Component.dispatchEvent(Unknown Source)
	at java.awt.EventQueue.dispatchEventImpl(Unknown Source)
	at java.awt.EventQueue.access$500(Unknown Source)
	at java.awt.EventQueue$3.run(Unknown Source)
	at java.awt.EventQueue$3.run(Unknown Source)
	at java.security.AccessController.doPrivileged(Native Method)
	at java.security.ProtectionDomain$JavaSecurityAccessImpl.doIntersectionPrivilege(Unknown Source)
	at java.security.ProtectionDomain$JavaSecurityAccessImpl.doIntersectionPrivilege(Unknown Source)
	at java.awt.EventQueue$4.run(Unknown Source)
	at java.awt.EventQueue$4.run(Unknown Source)
	at java.security.AccessController.doPrivileged(Native Method)
	at java.security.ProtectionDomain$JavaSecurityAccessImpl.doIntersectionPrivilege(Unknown Source)
	at java.awt.EventQueue.dispatchEvent(Unknown Source)
	at java.awt.EventDispatchThread.pumpOneEventForFilters(Unknown Source)
	at java.awt.EventDispatchThread.pumpEventsForFilter(Unknown Source)
	at java.awt.EventDispatchThread.pumpEventsForHierarchy(Unknown Source)
	at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
	at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
	at java.awt.EventDispatchThread.run(Unknown Source)
  • 写回答

3条回答 默认 最新

  • 一剑荒芜 2021-05-24 13:47
    关注

    String retStr = userDao.updatePassword(user,account,oldPassword);这行空指针了,断点一下看看userDao有值没,不会断点就输出userDao(System.out.println(userDao))

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(2条)

报告相同问题?

悬赏问题

  • ¥15 多电路系统共用电源的串扰问题
  • ¥15 shape_predictor_68_face_landmarks.dat
  • ¥15 slam rangenet++配置
  • ¥15 有没有研究水声通信方面的帮我改俩matlab代码
  • ¥15 对于相关问题的求解与代码
  • ¥15 ubuntu子系统密码忘记
  • ¥15 信号傅里叶变换在matlab上遇到的小问题请求帮助
  • ¥15 保护模式-系统加载-段寄存器
  • ¥15 电脑桌面设定一个区域禁止鼠标操作
  • ¥15 求NPF226060磁芯的详细资料