[英]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.