2013-02-19 77 views
-1

當過我嘗試編譯並運行這段代碼:我做錯了什麼?異常在線程「主要」 java.lang.NoSuchMethodError:主要

import java.awt.GridLayout; 
import java.awt.event.ActionListener; 

import javax.swing.JButton; 
import javax.swing.JFrame; 

public abstract class screen implements ActionListener { 
    private JFrame title = new JFrame("Tic-Tac-Toe"); 
    private JButton play = new JButton(""); 
    private JButton quit = new JButton(""); 

    public screen() { 

     /* Create Window */ 
     title.setSize(300,300); 
     title.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); 
     title.setLayout(new GridLayout(3,3)); 

     /* Add Buttons To The Window */ 
     title.add(play); 
     title.add(quit); 

     /* Action Listeners */ 
     play.addActionListener(this); 
     quit.addActionListener(this); 

     /* Make The Window Visible */ 
     title.setVisible(true); 

     /* Letters */ 
     play.setText("PLAY"); 
     quit.setText("QUIT"); 
    } 
} 

我得到這個:

Exception in thread "main" java.lang.NoSuchMethodError: main

我不知道我做了什麼錯誤。

我是新手。

請幫助!

+0

我在這裏看不到主要的方法。你有沒有嘗試在命令行上運行這個類?從這裏開始:http://docs.oracle.com/javase/tutorial/getStarted/cupojava/win32.html – duffymo 2013-02-19 23:46:32

+4

Ooo,ooo,我知道;沒有'主'。 – 2013-02-19 23:46:51

+0

需要一個主要方法來告訴你的程序從哪裏開始 – 2013-02-19 23:47:09

回答

0

您需要聲明public static void main(String args[]) {}方法。

+0

你把它放在哪裏 – user2089153 2013-02-20 00:07:56

+4

:: facepalm :: - 我認爲你可能想從一本關於Java的初學者的書開始,而不是揮動旗幟並希望飛機降落。 – 2013-02-20 00:08:33

+0

你可以在你的課堂上輸入。這種方法的知識和使用是最基本的核心Java技能之一,正如其他人一樣,我建議您在繼續之前嘗試遵循一些在線Java教程。從這裏開始:http://docs.oracle.com/javase/tutorial/ – JoshDM 2013-02-20 04:00:53

相關問題