簡體   English   中英

錯誤:找不到主要方法

[英]Error: Main method not found

Error: main method not found in class essence.Game, please define the main method as: public static void main(String[] args)

編碼:

package essence;

import static org.lwjgl.opengl.GL11.*;

import java.util.List;
import java.util.ArrayList;
import java.util.Random;

import org.lwjgl.input.*;
import org.lwjgl.opengl.*;
import org.lwjgl.*;

public class Game{

    List<Box> shapes = new ArrayList<Box>(16);

    public Game(){
        try {
            Display.setDisplayMode(new DisplayMode(800,600));
            Display.setTitle("Essence");
            Display.create();
        } catch (LWJGLException e){
            e.printStackTrace();
        }

        shapes.add(new Box(15, 15));
        shapes.add(new Box(100, 150));

        glMatrixMode(GL_PROJECTION);
        glLoadIdentity();
        glOrtho(0, 800, 600, 0, 1, -1);
        glMatrixMode(GL_MODELVIEW);

        while(!Display.isCloseRequested()){

            glClear(GL_COLOR_BUFFER_BIT);

            if(Keyboard.isKeyDown(Keyboard.KEY_ESCAPE)){
                Display.destroy();
                System.exit(0);
            }

            for (Box box : shapes) {
                box.draw();
            }

            Display.update();
            Display.sync(60);
        }
        Display.destroy();
    }

    private static class Box {
        public boolean selected = false;
        public int x, y;
        private float colorRed, colorBlue, colorGreen;

        Box (int x, int y){
            this.x = x;
            this.y = y;

            Random randomGenerator = new Random();

            colorRed = randomGenerator.nextFloat();
            colorBlue = randomGenerator.nextFloat();
            colorGreen = randomGenerator.nextFloat();   
        }

        boolean inBounds(int mouseX, int mouseY){
            if(mouseX > x && mouseX < x + 50 && mouseY > y && mouseY < y + 50)
                return true;
            else
                return false;
        }

        void randomizeColors(){
            Random randomGenerator = new Random();

            colorRed = randomGenerator.nextFloat();
            colorBlue = randomGenerator.nextFloat();
            colorGreen = randomGenerator.nextFloat();   
        }

        void update(int dx, int dy){
            x += dx;
            y += dy;
        }

        void draw(){
            glColor3f(colorRed, colorGreen, colorBlue);

            glBegin(GL_QUADS);
            glVertex2f(x, y);
            glVertex2f(x + 50, y);
            glVertex2f(x + 50, y + 50);
            glVertex2f(x, y + 50);
            glEnd();
        }

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

現在,假設我將其更改為:

package essence;

public class Game{

    public static void main(String[] args) {

    }
}

它仍然會給出相同的錯誤。 我檢查了文件夾布局,但確認其Eclipse\\Data\\workspace\\Essence\\src\\essenceEclipse\\Data\\workspace\\Essence\\bin\\essence

它不能是我的Java安裝,因為我的所有其他項目都能正常工作。 這是Eclipse中項目的屏幕截圖:

http://gyazo.com/296d53b33fa2619ca300c8a896d097dc

該錯誤的原因可能是什么,以及解決方法?

這也發生在我身上。 重新啟動編譯器可解決此問題。 例如,如果您正在運行Eclipse,只需重新啟動Eclipse。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM