0
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

此错误的原因可能是什么以及修复它的方法?

4

1 回答 1

0

它也发生在我身上。重新启动编译器可以解决问题。例如,如果您正在运行 Eclipse,只需重新启动 Eclipse。

于 2015-11-06T17:03:46.803 回答