Java 错误:找不到主方法
守则:Java 错误:找不到主方法,java,opengl,lwjgl,main,Java,Opengl,Lwjgl,Main,守则: Error: main method not found in class essence.Game, please define the main method as: public static void main(String[] args) 它仍然会给出相同的错误。我检查了文件夹布局,但确认其Eclipse\Data\workspace\essention\src\essention和Eclipse\Data\workspace\essention\bin\essention
Error: main method not found in class essence.Game, please define the main method as: public static void main(String[] args)
它仍然会给出相同的错误。我检查了文件夹布局,但确认其Eclipse\Data\workspace\essention\src\essention
和Eclipse\Data\workspace\essention\bin\essention
它不可能是我的Java安装,因为我的所有其他项目都可以正常工作。以下是Eclipse中项目的屏幕截图:
这个错误的原因和解决方法是什么?我也会遇到这种情况。重新启动编译器可修复此问题。例如,如果您正在运行Eclipse,只需重新启动Eclipse。您要在何处以及如何运行它?请尝试向类中添加故意的语法错误,然后重新编译/调用。我打赌你不会从编译器那里得到语法错误消息。这意味着您的环境正在拾取位于系统其他位置的已编译类的较旧版本。
ctrl+F11
不起作用,我正在尝试使用play
按钮在eclipse中运行它。清理项目没有效果。@DmitryBeransky我仍然得到错误:找不到或加载主类精华。如果我在任意位置键入lol
,游戏。我已删除.launch文件。bin文件夹为空。只有一件奇怪的事,当运行它时,我问我的朋友是运行游戏
还是游戏(1)
,不知道这是否重要?试试运行游戏(1)。eclipse认为您有两个游戏类,所以它在第二个类的后面附加了(1)。这些课程可能在不同的项目中,也可能不在不同的项目中。无论如何,它读错了。如果这不起作用,您可能需要交换工作空间并再次返回,或者清除一些缓存,或者类似的事情
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) {
}
}