2011-05-08 82 views
0

我正在探索java IDE的,現在我開始使用netbeans。我做了一個有兩個JFrame類的項目。我編輯了一些代碼,但我得到了一些錯誤。從我可以告訴它必須做我做的事情。我真的不能看到任何錯誤?也許你可以?Java應用程序問題 - Net beans

錯誤:

Exception in thread "main" java.lang.NoClassDefFoundError: com/actvtimer/ActivityFrame$1 
    at com.actvtimer.ActivityFrame.initComponents(ActivityFrame.java:49) 
    at com.actvtimer.ActivityFrame.<init>(ActivityFrame.java:26) 
    at com.actvtimer.ActivityFrame.main(ActivityFrame.java:155) 
Caused by: java.lang.ClassNotFoundException: com.actvtimer.ActivityFrame$1 
    at java.net.URLClassLoader$1.run(URLClassLoader.java:202) 
    at java.security.AccessController.doPrivileged(Native Method) 
    at java.net.URLClassLoader.findClass(URLClassLoader.java:190) 
    at java.lang.ClassLoader.loadClass(ClassLoader.java:307) 
    at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:301) 
    at java.lang.ClassLoader.loadClass(ClassLoader.java:248) 
    ... 3 more 

ActivityFrame.java:

/* 
* To change this template, choose Tools | Templates 
* and open the template in the editor. 
*/ 

/* 
* ActivityFrame.java 
* 
* Created on May 7, 2011, 5:29:14 PM 
*/ 
package com.actvtimer; 

import javax.swing.DefaultListModel; 
import javax.swing.UIManager; 
import javax.swing.UnsupportedLookAndFeelException; 

/** 
* 
* @author Andrew 
*/ 
public class ActivityFrame extends javax.swing.JFrame { 
    DefaultListModel model = new DefaultListModel(); 

    /** Creates new form ActivityFrame */ 
    public ActivityFrame() { 
     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() { 

     jScrollPane2 = new javax.swing.JScrollPane(); 
     jTable1 = new javax.swing.JTable(); 
     jButton1 = new javax.swing.JButton(); 
     jScrollPane1 = new javax.swing.JScrollPane(); 
     jList1 = new javax.swing.JList(); 
     jButton2 = new javax.swing.JButton(); 
     jButton3 = new javax.swing.JButton(); 

     setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE); 
     setTitle("Activity Timer"); 

     jTable1.setModel(new javax.swing.table.DefaultTableModel(
      new Object [][] { 

      }, 
      new String [] { 
       "Activity", "Time Allowed", "Time Left" 
      } 
     ) { 
      Class[] types = new Class [] { 
       java.lang.String.class, java.lang.Integer.class, java.lang.String.class 
      }; 
      boolean[] canEdit = new boolean [] { 
       false, true, false 
      }; 

      public Class getColumnClass(int columnIndex) { 
       return types [columnIndex]; 
      } 

      public boolean isCellEditable(int rowIndex, int columnIndex) { 
       return canEdit [columnIndex]; 
      } 
     }); 
     jScrollPane2.setViewportView(jTable1); 

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

     jList1.setModel(model); 
     jScrollPane1.setViewportView(jList1); 

     jButton2.setText("Start Activity"); 

     jButton3.setText("Stop Activity"); 

     javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane()); 
     getContentPane().setLayout(layout); 
     layout.setHorizontalGroup(
      layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) 
      .addComponent(jScrollPane2, javax.swing.GroupLayout.DEFAULT_SIZE, 464, Short.MAX_VALUE) 
      .addGroup(layout.createSequentialGroup() 
       .addComponent(jButton1) 
       .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) 
       .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 59, javax.swing.GroupLayout.PREFERRED_SIZE) 
       .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) 
       .addComponent(jButton2) 
       .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) 
       .addComponent(jButton3) 
       .addGap(108, 108, 108)) 
     ); 
     layout.setVerticalGroup(
      layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) 
      .addGroup(layout.createSequentialGroup() 
       .addComponent(jScrollPane2, javax.swing.GroupLayout.PREFERRED_SIZE, 90, javax.swing.GroupLayout.PREFERRED_SIZE) 
       .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) 
       .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) 
        .addComponent(jButton1) 
        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) 
         .addComponent(jButton2) 
         .addComponent(jButton3)) 
        .addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 68, Short.MAX_VALUE)) 
       .addContainerGap()) 
     ); 

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

    private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {           

       AddActivityFrame addAct = new AddActivityFrame(this); 
       addAct.setVisible(true); 
       addAct.setResizable(false); 

    }           

    public void addActivity(String name, int minutes) { 
     model.addElement(name); 


    } 
    /** 
    * @param args the command line arguments 
    */ 
    public static void main(String args[]) { 
      try { 
     // Set System L&F 
     UIManager.setLookAndFeel(
      UIManager.getSystemLookAndFeelClassName()); 
    } 
    catch (UnsupportedLookAndFeelException e) { 
     // handle exception 
    } 
    catch (ClassNotFoundException e) { 
     // handle exception 
    } 
    catch (InstantiationException e) { 
     // handle exception 
    } 
    catch (IllegalAccessException e) { 
     // handle exception 
    } 

       ActivityFrame app = new ActivityFrame(); 
       app.setVisible(true); 
       app.setResizable(false); 

    } 
    // Variables declaration - do not modify      
    private javax.swing.JButton jButton1; 
    private javax.swing.JButton jButton2; 
    private javax.swing.JButton jButton3; 
    private javax.swing.JList jList1; 
    private javax.swing.JScrollPane jScrollPane1; 
    private javax.swing.JScrollPane jScrollPane2; 
    private javax.swing.JTable jTable1; 
    // End of variables declaration     
} 
+0

'警告:請勿修改此代碼。' - 也許這是你問題的根源?你編輯了代碼嗎? – chemical 2011-05-08 17:12:28

+0

@chemical我根本沒有編輯該代碼! – 2011-05-08 17:13:42

+1

你能從命令提示符以外的Netbeans運行程序嗎? – 2011-05-08 17:37:29

回答

1

NoClassDefFound意味着 「沒有找到類定義」。

NoClassDefFound是JVM找不到運行Java程序所需的類的錯誤。此錯誤可能是由實際丟失的類​​造成的,但通常是由錯誤的CLASSPATH引起的。

我猜你的NetBeans配置安裝不正確。代碼似乎不是問題。

+0

也可能是因爲項目不乾淨。先嚐試乾淨的選項。 – chemical 2011-05-08 17:50:21

+0

嘿,清潔工作?但我仍然不知道什麼是錯的? – 2011-05-08 18:20:53

+0

好吧,這是因爲IDE並不總是訪問新鮮的代碼...很酷,它幫助。永遠記得刷新源代碼並清理:) (仍然很神祕你是如何設法從cmd行獲得同樣的錯誤的..你確定你做對了嗎?) – chemical 2011-05-08 18:39:58