我在尝试运行代码时遇到此错误,但看不出它有什么问题。
错误:线程“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){
}
}
答案 0 :(得分:7)
ERROR: Exception in thread "main" java.lang.NoSuchMethodError: main
我在这个类的任何地方都没有看到main
方法。你呢?
JVM查找main
方法,从该方法开始执行程序。 e.g。
public static void main (String[] args) {
new CheckerBoard();
}