尝试运行时出错:NoSuchMethodError:main

发布于 2024-10-31 15:05:26 字数 1934 浏览 3 评论 0原文

我在尝试运行代码时收到此错误,但看不出它出了什么问题。

错误:线程“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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

a√萤火虫的光℡ 2024-11-07 15:05:26
ERROR: Exception in thread "main" java.lang.NoSuchMethodError: main

我在此类中没有看到 main 方法。你?

JVM 会查找 main 方法,从该方法开始执行程序。例如

public static void main (String[] args) {
    new CheckerBoard();
}
ERROR: Exception in thread "main" java.lang.NoSuchMethodError: 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.

public static void main (String[] args) {
    new CheckerBoard();
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文