Eclipse / Jframe - 无法启动

时间:2015-07-01 12:10:09

标签: java eclipse swing

当我在eclipse中点击run / debug时,它给了我这个错误:

标题:无法启动 "无法启动选择,并且最近没有发布"

这是我的代码:

package jframe1;
import javax.swing.*;
public class jframe1 {
    public static void main(String args){
     JFrame frame = new JFrame();
     JButton button = new JButton("clikity");

     frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

     frame.getContentPane().add(button);

     frame.setSize(300, 300);
     frame.setVisible(true);
    }
}

如果我创建一个命令行应用程序,它运行正常,但是当我开始使用JFrame时,它无法运行我的代码/应用程序。

我该如何解决这个问题?问题在哪里?

2 个答案:

答案 0 :(得分:2)

    public static void main(String args){

应该是

    public static void main(String[] args){

答案 1 :(得分:2)

Eclipse无法找到您的main函数,因为您已经错误地声明了它 将.. main(String args)更改为.. main(String [] args)即可生效!

<强>代码:

import javax.swing.*;

public class jframe1 {

    // It's String[] args
    public static void main(String[] args) {
        JFrame frame = new JFrame();
        JButton button = new JButton("clikity");

        frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

        frame.getContentPane().add(button);

        frame.setSize(300, 300);
        frame.setVisible(true);
    }
}

<强>输出:

enter image description here