【问题标题】:Illegal start of expression on netbeans, not sure what the problem is [closed]netbeans 表达式的非法开始,不确定是什么问题[关闭]
【发布时间】:2022-11-23 09:35:16
【问题描述】:

下面的代码在 main 方法中给出了一个错误,说它是一个表达式的非法开始。谁能告诉我是否有任何语句未正确终止或缺少任何括号?还有什么问题?这是在 netbeans 上,我不是程序员。行话也不行。这是我的管理课程讲师的剪切粘贴作业。感谢您的任何帮助!!!

    private void AddButtonActionPerformed(java.awt.event.ActionEvent evt) {                                          
       try
       {
         Class.forName("net.ucanaccess.jdbc.UcanaccessDriver");
         String path = "C:\\MyDatabaseSDDNOV2022\\MyDatabaseSDDNOV2022.mdb";
         String url = "jdbc:ucanaccess://" + path;
         Connection c= DriverManager.getConnection(url);
          Statement stinsert=c.createStatement();
          String Sql = "Insert into Students(StudentName,StudentAge,EnrollmentDate,EnrolledCLasses,StudentAddress,StudentContactNumber,TeacherComment) Values (";
          Sql = Sql +"'" + txtSName.getText() +"','";
          Sql = Sql + txtSAge.getText() + "','";
          Sql = Sql + txtEDate.getText() + "','";
          Sql = Sql + txtEClass.getText() + "','";
          Sql = Sql + txtSAddress.getText() + "','";
          Sql = Sql + txtSContact.getText() + "','";
          Sql = Sql + txtTComment.getText() + "')";
              lblSql.setText(Sql);
              stinsert.executeUpdate(Sql);
              lblSql.setText("Record Inserted");
       
     
    }                                         
       catch (Exception E) {
    /**
     * @param args the command line arguments
     */
    
    public static void main(String args[]) {
        /* Set the Nimbus look and feel */
        //<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) ">
        /* If Nimbus (introduced in Java SE 6) is not available, stay with the default look and feel.
         * For details see http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html 
         */
        try {
            for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
                if ("Nimbus".equals(info.getName())) {
                    javax.swing.UIManager.setLookAndFeel(info.getClassName());
                    break;
                }
            }
        } catch (ClassNotFoundException ex) {
            java.util.logging.Logger.getLogger(TestingSDDNOV2022.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (InstantiationException ex) {
            java.util.logging.Logger.getLogger(TestingSDDNOV2022.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (IllegalAccessException ex) {
            java.util.logging.Logger.getLogger(TestingSDDNOV2022.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (javax.swing.UnsupportedLookAndFeelException ex) {
            java.util.logging.Logger.getLogger(TestingSDDNOV2022.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        }
        //</editor-fold>

        /* Create and display the form */
        java.awt.EventQueue.invokeLater(new Runnable() {
            public void run() {
                new TestingSDDNOV2022().setVisible(true);
            }
        });
    }

    // Variables declaration - do not modify                     
    private javax.swing.JButton AddButton;
    private javax.swing.JButton DeleteButton;
    private javax.swing.JButton EditButton;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JLabel jLabel4;
    private javax.swing.JLabel jLabel5;
    private javax.swing.JLabel jLabel6;
    private javax.swing.JLabel jLabel7;
    private javax.swing.JLabel jLabel8;
    private javax.swing.JPanel jPanel1;
    private javax.swing.JLabel lblSql;
    private javax.swing.JTextField txtEClass;
    private javax.swing.JTextField txtEDate;
    private javax.swing.JTextField txtSAddress;
    private javax.swing.JTextField txtSAge;
    private javax.swing.JTextField txtSContact;
    private javax.swing.JTextField txtSName;
    private javax.swing.JTextField txtTComment;
    // End of variables declaration                   
}

不是程序员,所以我尝试在不同的行上添加分号和括号,但没有任何效果。再次感谢你!

【问题讨论】:

  • 您的示例以 private void AddButtonActionPerformed(java.awt.event.ActionEvent evt) 开头,但方法需要放置在某些引用类型中。所以很可能你有类似import ...; class ABC{ private void AddButtonActionPerformed(java.awt.event.ActionEvent evt) { ... } }的东西,但你没有复制粘贴它的开头import ...; class ABC{

标签: java netbeans


【解决方案1】:

catch 语句之后你缺少 2 个右大括号:

       catch (Exception E) {
    /**
     * @param args the command line arguments
     */

应该:

        } catch (Exception E) {

        }
    }
    
    /**
     * @param args the command line arguments
     */

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2021-06-05
    • 2015-05-30
    • 1970-01-01
    • 1970-01-01
    • 2015-03-06
    • 2011-01-15
    • 1970-01-01
    • 2019-02-22
    相关资源
    最近更新 更多