2013-02-19 266 views
0

我正在使用Netbeans来编写一个Java程序。我想这个程序基本上打开一个应用程序,但它在一个区域..(Windows已经完成了..但W/E)。 当我打开这个程序时,正如它在标题中所说的那样,我收到错误“无法加载或找到主要类”我不知道为什么我要这样做,因为我所做的其他程序大多数都没有有这个问题。Java无法加载或找到主类

/* 
* To change this template, choose Tools | Templates 
* and open the template in the editor. 
*/ 
package org.javaapplication10; 
import java.io.*; 
/** 
* 
* @author Ethan 
*/ 
public class javaapplication10 extends javax.swing.JFrame { 

    /** 
    * Creates new form javaapplication10 
    */ 
    public javaapplication10() { 
     initComponents(); 
    } 

    /** 
    * This method is called from within the constructor to initialize the form. 
    * WARNING: Do NOT modify this code. The content of this method is always 
    * regenerated by the Form Editor. 
    */ 
    @SuppressWarnings("unchecked") 
    // <editor-fold defaultstate="collapsed" desc="Generated Code">       
    private void initComponents() { 

     jButton1 = new javax.swing.JButton(); 
     jButton2 = new javax.swing.JButton(); 
     jButton3 = new javax.swing.JButton(); 
     jButton4 = new javax.swing.JButton(); 

     setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE); 

     jButton1.setText("Minecraft"); 
     jButton1.addActionListener(new java.awt.event.ActionListener() { 
      public void actionPerformed(java.awt.event.ActionEvent evt) { 
       jButton1ActionPerformed(evt); 
      } 
     }); 

     jButton2.setText("FTB"); 

     jButton3.setText("Tekkit"); 

     jButton4.setText("Chrome"); 

     javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane()); 
     getContentPane().setLayout(layout); 
     layout.setHorizontalGroup(
      layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) 
      .addComponent(jButton3, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) 
      .addGroup(layout.createSequentialGroup() 
       .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false) 
        .addComponent(jButton1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) 
        .addComponent(jButton2, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)) 
       .addGap(0, 0, Short.MAX_VALUE)) 
      .addComponent(jButton4, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) 
     ); 
     layout.setVerticalGroup(
      layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) 
      .addGroup(layout.createSequentialGroup() 
       .addComponent(jButton1) 
       .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) 
       .addComponent(jButton2) 
       .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) 
       .addComponent(jButton3) 
       .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) 
       .addComponent(jButton4)) 
     ); 

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

    private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {           
try { 
     String line; 
     Process p = Runtime.getRuntime().exec("cmd C:\\Users\\Ethan\\Desktop\\minecraft.bat"); 
     BufferedReader bri = new BufferedReader 
     (new InputStreamReader(p.getInputStream())); 
     BufferedReader bre = new BufferedReader 
     (new InputStreamReader(p.getErrorStream())); 
     while ((line = bri.readLine()) != null) { 
     System.out.println(line); 
     } 
     bri.close(); 
     while ((line = bre.readLine()) != null) { 
     System.out.println(line); 
     } 
     bre.close(); 
     p.waitFor(); 
     System.out.println("Done."); 
    } 
    catch (Exception err) { 
     err.printStackTrace(); 
    }           
    } 
    /** 
    * @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(javaapplication10.class.getName()).log(java.util.logging.Level.SEVERE, null, ex); 
     } catch (InstantiationException ex) { 
      java.util.logging.Logger.getLogger(javaapplication10.class.getName()).log(java.util.logging.Level.SEVERE, null, ex); 
     } catch (IllegalAccessException ex) { 
      java.util.logging.Logger.getLogger(javaapplication10.class.getName()).log(java.util.logging.Level.SEVERE, null, ex); 
     } catch (javax.swing.UnsupportedLookAndFeelException ex) { 
      java.util.logging.Logger.getLogger(javaapplication10.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 javaapplication10().setVisible(true); 
      } 
     }); 
    } 
    // Variables declaration - do not modify      
    private javax.swing.JButton jButton1; 
    private javax.swing.JButton jButton2; 
    private javax.swing.JButton jButton3; 
    private javax.swing.JButton jButton4; 
    // End of variables declaration     
} 

在NetBeans中,我有一些看起来像这样: “JavaApplication10” “源代码包” “javaapplication10” “javaapplication10.java”

+0

运行它如何?它是Jar'ed还是你从Netbeans内运行?如果是Jar'ed,您是否在MANIFEST.mf文件中设置了“Main-Class”条目? – MadProgrammer 2013-02-19 01:04:22

+0

再次感谢madprogrammer,但是如何设置主类?我要添加什么? – Leetfail 2013-02-19 01:05:24

+3

从Netbeans中,右键单击'Projects'选项卡中的项目节点,选择'Properties'。浏览到“运行”节点。它说'Main Class',选择Browse并选择你想要执行的类。据推测,这将是'javaapplication10' – MadProgrammer 2013-02-19 01:07:29

回答

2

enter image description here

确保您主要类别字段具有正确的值。在你的情况下,它应该是org.javaapplication10.javaapplication10

相关问题