简体   繁体   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)

The code: 编码:

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();
    }
}

Now let's say I change it to: 现在,假设我将其更改为:

package essence;

public class Game{

    public static void main(String[] args) {

    }
}

It will still give the same error. 它仍然会给出相同的错误。 I checked the folder layout, but I confirmed that its Eclipse\\Data\\workspace\\Essence\\src\\essence and Eclipse\\Data\\workspace\\Essence\\bin\\essence 我检查了文件夹布局,但确认其Eclipse\\Data\\workspace\\Essence\\src\\essenceEclipse\\Data\\workspace\\Essence\\bin\\essence

It cannot be my Java installation, because all my other projects work fine. 它不能是我的Java安装,因为我的所有其他项目都能正常工作。 Here's a screenshot of the project within Eclipse: 这是Eclipse中项目的屏幕截图:

http://gyazo.com/296d53b33fa2619ca300c8a896d097dc http://gyazo.com/296d53b33fa2619ca300c8a896d097dc

What could be the cause of this error and the way to fix it? 该错误的原因可能是什么,以及解决方法?

It happens to me as well. 这也发生在我身上。 Restarting the Compiler fix the problem. 重新启动编译器可解决此问题。 For Example, If you are running Eclipse, just restart Eclipse. 例如,如果您正在运行Eclipse,只需重新启动Eclipse。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM