问题遇到的现象和发生背景
问题相关代码,请勿粘贴截图
/**
* Launch the application.
*/
public static void main(String[] args) {
EventQueue.invokeLater(new Runnable() {
public void run() {
try {
studentstelylogin window = new studentstelylogin();
window.frame.setVisible(true);
} catch (Exception e) {
e.printStackTrace();
}
}
});
}
/**
* Create the application.
*/
public studentstelylogin() {
initialize();
}
/**
* Initialize the contents of the frame.
*/
private void initialize() {
frame = new JFrame();
frame.setBounds(400, 200, 450, 300);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setVisible(true);
frame.setResizable(false);
frame.getContentPane().setLayout(null);
JLabel j1=new JLabel("***欢迎登陆学生信息管理系统***");
j1.setBounds(120, 26, 180, 15);
frame.getContentPane().add(j1);
JLabel lblNewLabel = new JLabel("用户名:");
lblNewLabel.setBounds(100, 56, 54, 15);
frame.getContentPane().add(lblNewLabel);
JLabel lblNewLabel_1 = new JLabel("密码:");
lblNewLabel_1.setBounds(100, 102, 54, 15);
frame.getContentPane().add(lblNewLabel_1);
textField = new JTextField();
textField.setBounds(196, 53, 100, 21);
frame.getContentPane().add(textField);
textField.setColumns(10);
passwordField = new JPasswordField();
passwordField.setBounds(196, 96,100, 21);
frame.getContentPane().add(passwordField);
JButton btnNewButton = new JButton("登录");
btnNewButton.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
shujuku c = new shujuku();
Connection conn = c.getConnect();
PreparedStatement ps = null;
ResultSet rs = null;
try {
ps = conn
.prepareStatement("select *from userinfo where username=? and password=?");
ps.setString(1, textField.getText());
ps.setString(2, passwordField.getText());
rs = ps.executeQuery();
if (rs.next()) {
try {
new studentstelylogin();
frame.removeNotify();
} catch (ClassNotFoundException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
}
} else {
JOptionPane pane = new JOptionPane("用户或密码错误");
JDialog dialog = pane.createDialog("警告");
dialog.show();
}
} catch (SQLException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
}
}
});
btnNewButton.setBounds(41, 169, 93, 23);
frame.getContentPane().add(btnNewButton);
JButton btnNewButton_1 = new JButton("注册");
btnNewButton_1.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
frame.removeNotify();
}
});
btnNewButton_1.setBounds(183, 169, 93, 23);
frame.getContentPane().add(btnNewButton_1);
JButton j2 = new JButton("退出");
j2.setBounds(323, 169, 93, 23);
frame.getContentPane().add(j2);
j2.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
// TODO 自动生成的方法存根
if(e.getActionCommand().equals("退出")){
System.exit(0);
}
}
});
}
private void add(JButton quitBt2) {
// TODO Auto-generated method stub
}
private Container getContentPane() {
// TODO Auto-generated method stub
return null;
}
}
运行结果及报错内容
Exception in thread "AWT-EventQueue-0" java.lang.Error: 无法解析的编译问题:
执行不到的 ClassNotFoundException 的 catch 块。从未从 try 语句主体抛出此异常
at qmks/实训.studentstelylogin$2.actionPerformed(studentstelylogin.java:112)
at java.desktop/javax.swing.AbstractButton.fireActionPerformed(AbstractButton.java:1967)
at java.desktop/javax.swing.AbstractButton$Handler.actionPerformed(AbstractButton.java:2308)
at java.desktop/javax.swing.DefaultButtonModel.fireActionPerformed(DefaultButtonModel.java:405)
at java.desktop/javax.swing.DefaultButtonModel.setPressed(DefaultButtonModel.java:262)
at java.desktop/javax.swing.plaf.basic.BasicButtonListener.mouseReleased(BasicButtonListener.java:279)
at java.desktop/java.awt.Component.processMouseEvent(Component.java:6614)
at java.desktop/javax.swing.JComponent.processMouseEvent(JComponent.java:3342)
at java.desktop/java.awt.Component.processEvent(Component.java:6379)
at java.desktop/java.awt.Container.processEvent(Container.java:2263)
at java.desktop/java.awt.Component.dispatchEventImpl(Component.java:4990)
at java.desktop/java.awt.Container.dispatchEventImpl(Container.java:2321)
at java.desktop/java.awt.Component.dispatchEvent(Component.java:4822)
at java.desktop/java.awt.LightweightDispatcher.retargetMouseEvent(Container.java:4919)
at java.desktop/java.awt.LightweightDispatcher.processMouseEvent(Container.java:4548)
at java.desktop/java.awt.LightweightDispatcher.dispatchEvent(Container.java:4489)
at java.desktop/java.awt.Container.dispatchEventImpl(Container.java:2307)
at java.desktop/java.awt.Window.dispatchEventImpl(Window.java:2769)
at java.desktop/java.awt.Component.dispatchEvent(Component.java:4822)
at java.desktop/java.awt.EventQueue.dispatchEventImpl(EventQueue.java:772)
at java.desktop/java.awt.EventQueue$4.run(EventQueue.java:721)
at java.desktop/java.awt.EventQueue$4.run(EventQueue.java:715)
at java.base/java.security.AccessController.doPrivileged(AccessController.java:391)
at java.base/java.security.ProtectionDomain$JavaSecurityAccessImpl.doIntersectionPrivilege(ProtectionDomain.java:85)
at java.base/java.security.ProtectionDomain$JavaSecurityAccessImpl.doIntersectionPrivilege(ProtectionDomain.java:95)
at java.desktop/java.awt.EventQueue$5.run(EventQueue.java:745)
at java.desktop/java.awt.EventQueue$5.run(EventQueue.java:743)
at java.base/java.security.AccessController.doPrivileged(AccessController.java:391)
at java.base/java.security.ProtectionDomain$JavaSecurityAccessImpl.doIntersectionPrivilege(ProtectionDomain.java:85)
at java.desktop/java.awt.EventQueue.dispatchEvent(EventQueue.java:742)
at java.desktop/java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:203)
at java.desktop/java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:124)
at java.desktop/java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:113)
at java.desktop/java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:109)
at java.desktop/java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:101)
at java.desktop/java.awt.EventDispatchThread.run(EventDispatchThread.java:90)