選擇不包含主要類型 - 錯誤 (Selection does not contain main type - error)


問題描述

選擇不包含主要類型 ‑ 錯誤 (Selection does not contain main type ‑ error)

I'm working on a lab for class and it's my first GUI environment. When I try to run the program it asks me "Select a way to run 'Lab 8'" and then two options ‑ Java Applet or Java Application. It doesn't matter which I choose, I then get an error message "Selection does not contain a main type." Do I need to do anything for Eclipse to create GUI programs, like an add‑on or something?

This is the only code I have so far. Not sure if that matters. Thanks

import javax.swing.*;
import java.awt.*;

public class TicTacToe extends JFrame{
    private ImageIcon cross = new ImageIcon ("FlowerX.jpg");
    ImageIcon not = new ImageIcon ("Owl.gif");

    public TicTacToe(){
        Container container = getContentPane();
        container.setLayout(new GridLayout(3, 3));


        }

    }

參考解法

方法 1:

You need to have a main method in a standalone java program to run. The main method as specidifed below is the starting point for the jvm to execute your program:

public static void main (String args[])

Modify your code like this and try to execute:

import javax.swing.*;
import java.awt.*;

public class TicTacToe extends JFrame{
    private ImageIcon cross = new ImageIcon ("FlowerX.jpg");
    ImageIcon not = new ImageIcon ("Owl.gif");

    public TicTacToe(){
        Container container = getContentPane();
        container.setLayout(new GridLayout(3, 3));

      }

      public static void main(String args[])
      {
          new TicTacToe();
      }

    }

Learn more about main and basic structure of a java application: http://docs.oracle.com/javase/tutorial/getStarted/application/

(by AhviaaJuned Ahsan)

參考文件

  1. Selection does not contain main type ‑ error (CC BY‑SA 3.0/4.0)

#runtime #java #user-interface






相關問題

通過java運行的執行程序似乎超時? (Executed programs run through java seem to time out?)

Kesalahan NullPointerException dalam kode Java saya. (NullPointerException errors in my Java code.)

Hentikan proses anak ketika proses induk berhenti (Stop child process when parent process stops)

Атрымаць шлях выканання кансольнага скрыпта Python (Get the runpath of a python console-script)

選擇不包含主要類型 - 錯誤 (Selection does not contain main type - error)

在活動之間使用意圖錯誤 (using intents between activities error)

在運行時使用 Spring 在表中創建新字段 (Create new field into a table with Spring at runtime)

如何添加運行時超時以防止 java.net.SocketTimeoutException? (How do I add a runtime timeout to prevent java.net.SocketTimeoutException?)

我有什麼方法可以覆蓋 Java 中的系統屬性嗎? (Do I have any method to override System Properties in Java?)

如何計算此代碼的時間複雜度? (How can I compute the time complexity of this code?)

運行 .exe 文件生成 bt jar2exe 軟件時出現 java runtime environment not found 錯誤 (Getting java runtime enviroment not found error while running .exe file produced bt jar2exe software)

在運行時在 VBA 中顯示所有變量及其值 (Show all variables and their values in VBA during runtime)







留言討論