错误:找不到主方法


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) {
    }
}

它仍然会给出相同的错误。我检查了文件夹布局,但我确认它EclipseDataworkspaceEssencesrcessenceEclipseDataworkspaceEssencebinessence

它不可能是我的 Java 安装,因为我的所有其他项目都运行良好。以下是 Eclipse 中项目的屏幕截图:

http://gyazo.com/296d53b33fa2619ca300c8a896d097dc

此错误的原因以及解决方法可能是什么?

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

相关内容

  • 没有找到相关文章