[英]Eclipse / Jframe - Unable to Launch
When I click on run/debug in eclipse, it gives me this error: 当我在Eclipse中单击运行/调试时,它给了我这个错误:
Title:Unable to Launch "The selection cannot be launched and there are no recent launches" 标题:无法启动“无法启动选择,并且最近没有启动”
Here is my code: 这是我的代码:
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);
}
}
It runs fine if I make a command line application, but not when I start using JFrame I cannot run my code/application. 如果我创建了命令行应用程序,它将运行良好,但是当我开始使用JFrame时,它将无法运行我的代码/应用程序。
How do I fix this? 我该如何解决? Where is the problem?
问题出在哪儿?
public static void main(String args){
应该
public static void main(String[] args){
Eclipse can't find your main
function as you have declared it wrongly. Eclipse找不到您的
main
函数,因为您已错误地声明了它。
Change .. main(String args)
to .. main(String [] args)
and it will work! 将
.. main(String args)
更改为.. main(String [] args)
,它将起作用!
Code: 码:
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);
}
}
Output: 输出:
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.