繁体   English   中英

Eclipse / Jframe-无法启动

[英]Eclipse / Jframe - Unable to Launch

当我在Eclipse中单击运行/调试时,它给了我这个错误:

标题:无法启动“无法启动选择,并且最近没有启动”

这是我的代码:

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时,它将无法运行我的代码/应用程序。

我该如何解决? 问题出在哪儿?

    public static void main(String args){

应该

    public static void main(String[] args){

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);
    }
}

输出:

在此处输入图片说明

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM