Java报错exception in thread awt-eventqueue-0这个怎么解决呀

这篇具有很好参考价值的文章主要介绍了Java报错exception in thread awt-eventqueue-0这个怎么解决呀。希望对大家有所帮助。如果存在错误或未考虑完全的地方,请大家不吝赐教,您也可以点击"举报违法"按钮提交疑问。

public void actionPerformed(ActionEvent e) {

  flag=0;

     try{

   String num,name,gender,address,phone,major;

   con=DriverManager.getConnection("jdbc:mysql://localhost:3306/university?characterEncoding=utf8","root","123456");

   num=t1.getText().trim();

   ResultSet rs=sql.executeQuery("SELECT * FROM student WHERE id='"+num+"'");

   if(rs.next()){

       name=rs.getString("name");

       gender=rs.getString("gender");

       address=rs.getString("address");

       phone=rs.getString("phone");

       major=rs.getString("major");

         t2.setText(name);

         t3.setText(gender);

         t4.setText(address);

         t5.setText(phone);

         t6.setText(major);

         if(e.getSource()==b2){

         String temp="DELETE FROM student WHERE id='"+num+"'";

       sql.executeUpdate(temp);

  JOptionPane.showMessageDialog(this,"删除成功!","提示对话框",JOptionPane.INFORMATION_MESSAGE);

         }

         flag=1;

   }else{

      JOptionPane.showMessageDialog(this,"没有该学生!","提示对话框",JOptionPane.INFORMATION_MESSAGE);

   }

   con.close();

   if(flag==0){t1.setText("没有该学生");}

   }

     catch(SQLException ee){}

 }

}

错误

Exception in thread "AWT-EventQueue-0" java.lang.NullPointerException: Cannot invoke "java.sql.Statement.executeQuery(String)" because "this.sql" is null

 at GUI.StudentDelete.actionPerformed(StudentDelete.java:90)

 at java.desktop/javax.swing.AbstractButton.fireActionPerformed(AbstractButton.java:1972)

 at java.desktop/javax.swing.AbstractButton$Handler.actionPerformed(AbstractButton.java:2313)

 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:6626)

 at java.desktop/javax.swing.JComponent.processMouseEvent(JComponent.java:3389)

 at java.desktop/java.awt.Component.processEvent(Component.java:6391)

 at java.desktop/java.awt.Container.processEvent(Container.java:2266)

 at java.desktop/java.awt.Component.dispatchEventImpl(Component.java:5001)

 at java.desktop/java.awt.Container.dispatchEventImpl(Container.java:2324)

 at java.desktop/java.awt.Component.dispatchEvent(Component.java:4833)

 at java.desktop/java.awt.LightweightDispatcher.retargetMouseEvent(Container.java:4948)

 at java.desktop/java.awt.LightweightDispatcher.processMouseEvent(Container.java:4575)

 at java.desktop/java.awt.LightweightDispatcher.dispatchEvent(Container.java:4516)

 at java.desktop/java.awt.Container.dispatchEventImpl(Container.java:2310)

 at java.desktop/java.awt.Window.dispatchEventImpl(Window.java:2780)

 at java.desktop/java.awt.Component.dispatchEvent(Component.java:4833)

 at java.desktop/java.awt.EventQueue.dispatchEventImpl(EventQueue.java:773)

 at java.desktop/java.awt.EventQueue$4.run(EventQueue.java:722)

 at java.desktop/java.awt.EventQueue$4.run(EventQueue.java:716)

 at java.base/java.security.AccessController.doPrivileged(AccessController.java:399)

 at java.base/java.security.ProtectionDomain$JavaSecurityA

exception in thread

 文章来源地址https://www.toymoban.com/news/detail-766486.html

到了这里,关于Java报错exception in thread awt-eventqueue-0这个怎么解决呀的文章就介绍完了。如果您还想了解更多内容,请在右上角搜索TOY模板网以前的文章或继续浏览下面的相关文章,希望大家以后多多支持TOY模板网!

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处: 如若内容造成侵权/违法违规/事实不符,请点击违法举报进行投诉反馈,一经查实,立即删除!

领支付宝红包 赞助服务器费用

相关文章

觉得文章有用就打赏一下文章作者

支付宝扫一扫打赏

博客赞助

微信扫一扫打赏

请作者喝杯咖啡吧~博客赞助

支付宝扫一扫领取红包,优惠每天领

二维码1

领取红包

二维码2

领红包