2011-04-11 152 views
0

嘗試運行我的代碼時出現此錯誤,但看不到它出現了什麼問題。嘗試運行時出錯:NoSuchMethodError:main

ERROR: Exception in thread "main" java.lang.NoSuchMethodError: main

import java.awt.*; 
import java.awt.event.*; 

public class Checkerboard extends Frame implements ActionListener { 

    Button btnGo = new Button ("Go"); 
    Button btnClear = new Button("Clear"); 

    Label lblStart = new Label("Start"); 
    Label lblStop = new Label("Stop"); 
    Label lblStep = new Label("Step"); 

    TextField txtStart = new TextField(10); 
    TextField txtStop = new TextField(10); 
    TextField txtStep = new TextField(10); 

    Panel pnlCenter = new Panel(); 
    Panel pnlSouth = new Panel(); 
    Panel pnlInput = new Panel(); 
    Panel pnlButton = new Panel(); 

    GridLayout gridColors = new GridLayout(4,4); 
    GridLayout gridInput = new GridLayout(2,3); 

    TextField txtArray[]; 

    public Checkerboard() { 
     txtArray = new TextField[16]; 

     addWindowListener(new WindowAdapter() { 
      public void windowClosing (WindowEvent e) { 
       System.exit(0); 
      } 
     }); 

     btnGo.addActionListener(this); 
     btnClear.addActionListener(this); 
     setLayout(new BorderLayout()); 
     pnlCenter.setLayout(gridColors); 

     for(int i = 0; i < 16; i++) { 
        txtArray[i] = new TextField(Integer.toString(i)); 
        txtArray[i].setEditable(false); 
        txtArray[i].setBackground(Color.white); 
        pnlCenter.add(txtArray[i]); 


     } 
     pnlInput.setLayout(gridInput); 
     pnlInput.add(txtStart); 
     pnlInput.add(txtStop); 
     pnlInput.add(txtStep); 
     pnlInput.add(lblStart); 
     pnlInput.add(lblStop); 
     pnlInput.add(lblStep); 
     pnlButton.add(btnGo); 
     pnlButton.add(btnClear); 
     add("Center", pnlCenter); 
    } 
    public void actionPerformed(ActionEvent e){   
    }  
} 
+1

的java!= JavaScript的 – 2011-04-11 03:32:53

+0

您可能要回來檢查過你的一些問題的答案,我懷疑你在他們中間有不到25%的正確的解決方案。 – 2011-04-11 04:08:21

+0

[java.lang.NoSuchMethodError:線程main中的main異常的原因']的可能的重複(http://stackoverflow.com/questions/5407250/causes-of-java-lang-nosuchmethoderror-main-exception-在線程主) – 2011-04-11 05:44:46

回答

7
ERROR: Exception in thread "main" java.lang.NoSuchMethodError: main 

我沒有在這個類中看到一個main方法的任何地方。你做?

JVM查找main方法,從中開始執行程序。例如

public static void main (String[] args) { 
    new CheckerBoard(); 
}