无法运行JFrames

时间:2019-12-02 09:53:58

标签: java swing netbeans jframe portability

我最近在使用netbeans时遇到了很多麻烦,我现在使用的是便携式版本(Apache NetBeans IDE 11.2),使用的是JDK 13.0.1,每当我尝试运行最简单的JFrame时,它们都会因此错误而崩溃:

C:\Users\banhi\AppData\Local\NetBeans\Cache\11.2\executor-snippets\run.xml:111: The following error occurred while executing this line:
C:\Users\banhi\AppData\Local\NetBeans\Cache\11.2\executor-snippets\run.xml:68: Java returned: -1073740771
BUILD FAILED (total time: 3 seconds)

我要做的就是创建一个没有main的应用程序,然后在默认packate中创建一个JFrame(仅用于测试)并添加一个按钮:


public class JFnis extends javax.swing.JFrame {


    public JFnis() {
        initComponents();
    }


    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">                          
    private void initComponents() {

        jButton1 = new javax.swing.JButton();

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);

        jButton1.setText("jButton1");

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addGap(117, 117, 117)
                .addComponent(jButton1)
                .addContainerGap(210, Short.MAX_VALUE))
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addGap(115, 115, 115)
                .addComponent(jButton1)
                .addContainerGap(162, Short.MAX_VALUE))
        );

        pack();
    }// </editor-fold>                        


    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(JFnis.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (InstantiationException ex) {
            java.util.logging.Logger.getLogger(JFnis.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (IllegalAccessException ex) {
            java.util.logging.Logger.getLogger(JFnis.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (javax.swing.UnsupportedLookAndFeelException ex) {
            java.util.logging.Logger.getLogger(JFnis.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 JFnis().setVisible(true);
            }
        });
    }

    // Variables declaration - do not modify                     
    private javax.swing.JButton jButton1;
    // End of variables declaration                   
}


  • .java类工作正常
  • Source / Binary和Java平台都设置为JDK 13
  • 我可以很好地清理和构建项目

1 个答案:

答案 0 :(得分:1)

我在我的IDE中运行您的代码-IntelliJ, 效果很好:

Your code by IntelliJ

您的IDE配置似乎有问题,可能缺少一些环境变量,或者尝试重新创建项目。

如果您不想替换为另一个IDE(例如Eclipse / IntelliJ),则可以尝试遵循建议的解决方案here