尝试运行时出错:NoSuchMethodError:main
我在尝试运行代码时收到此错误,但看不出它出了什么问题。
错误:线程“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){
}
}
I get this error when trying to run my code, but can't see what's wrong with it.
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){
}
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我在此类中没有看到
main
方法。你?JVM 会查找
main
方法,从该方法开始执行程序。例如I don't see a
main
method anywhere in this class. Do you?The JVM looks for a
main
method from which the execution of your program begins. e.g.