Eclipse:线程中的异常;游戏“;java.lang.IllegalStateException:请使用-XstartOnFirstThread运行JVM

Eclipse:线程中的异常;游戏“;java.lang.IllegalStateException:请使用-XstartOnFirstThread运行JVM,java,eclipse,Java,Eclipse,我正在学习如何在eclipse(java)上制作flappy bird。我遵循了视频中的所有说明,但视频中显示了以下错误: Exception in thread "Game" java.lang.IllegalStateException: Please run the JVM with -XstartOnFirstThread. at org.lwjgl.system.macosx.EventLoop.checkFirstThread(EventLoop.java:20) at org.lw

我正在学习如何在eclipse(java)上制作flappy bird。我遵循了视频中的所有说明,但视频中显示了以下错误:

Exception in thread "Game" java.lang.IllegalStateException: Please run the JVM with -XstartOnFirstThread.
at org.lwjgl.system.macosx.EventLoop.checkFirstThread(EventLoop.java:20)
at org.lwjgl.glfw.GLFW.glfwInit(GLFW.java:426)
at com.thecherno.flappy.Main.init(Main.java:37)
at com.thecherno.flappy.Main.run(Main.java:79)
at java.lang.Thread.run(Thread.java:745)
文件位置正确,但出现了错误。以下是主要类别代码:

package com.thecherno.flappy;

import static org.lwjgl.glfw.GLFW.*;
import static org.lwjgl.opengl.GL11.*;
import static org.lwjgl.opengl.GL13.*;
import static org.lwjgl.system.MemoryUtil.*;
import java.nio.ByteBuffer;
import org.lwjgl.glfw.GLFWvidmode;
import org.lwjgl.opengl.GLContext;
import com.thecherno.flappy.graphics.Shader;
import com.thecherno.flappy.input.Input;
import com.thecherno.flappy.level.Level;
import com.thecherno.flappy.maths.Matrix4f;

public class Main implements Runnable {

private int width = 1280;
private int height = 720;

private Thread thread;
private boolean running = false;

private long window;

private Level level;

public void start() {
    running = true;
    thread = new Thread(this, "Game");
    thread.start();
}

private void init() {
    if (glfwInit() != GL_TRUE) {
        System.err.println("Could not initialize GLFW!");
        return;
    }

    glfwWindowHint(GLFW_RESIZABLE, GL_TRUE);
    window = glfwCreateWindow(width, height, "Flappy", NULL, NULL);
    if (window == NULL) {
        System.err.println("Could not create GLFW window!");
        return;
    }

    ByteBuffer vidmode = glfwGetVideoMode(glfwGetPrimaryMonitor());
    glfwSetWindowPos(window, (GLFWvidmode.width(vidmode) - width) / 2, (GLFWvidmode.height(vidmode) - height) / 2);

    glfwSetKeyCallback(window, new Input());

    glfwMakeContextCurrent(window);
    glfwShowWindow(window);
    GLContext.createFromCurrent();

    glEnable(GL_DEPTH_TEST);
    glActiveTexture(GL_TEXTURE1);
    glEnable(GL_BLEND);
    glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
    System.out.println("OpenGL: " + glGetString(GL_VERSION));
    Shader.loadAll();

    Matrix4f pr_matrix = Matrix4f.orthographic(-10.0f, 10.0f, -10.0f * 9.0f / 16.0f, 10.0f * 9.0f / 16.0f, -1.0f, 1.0f);
    Shader.BG.setUniformMat4f("pr_matrix", pr_matrix);
    Shader.BG.setUniform1i("tex", 1);

    Shader.BIRD.setUniformMat4f("pr_matrix", pr_matrix);
    Shader.BIRD.setUniform1i("tex", 1);

    Shader.PIPE.setUniformMat4f("pr_matrix", pr_matrix);
    Shader.PIPE.setUniform1i("tex", 1);

    level = new Level();
}

public void run() {
    init();

    long lastTime = System.nanoTime();
    double delta = 0.0;
    double ns = 1000000000.0 / 60.0;
    long timer = System.currentTimeMillis();
    int updates = 0;
    int frames = 0;
    while (running) {
        long now = System.nanoTime();
        delta += (now - lastTime) / ns;
        lastTime = now;
        if (delta >= 1.0) {
            update();
            updates++;
            delta--;
        }
        render();
        frames++;
        if (System.currentTimeMillis() - timer > 1000) {
            timer += 1000;
            System.out.println(updates + " ups, " + frames + " fps");
            updates = 0;
            frames = 0;
        }
        if (glfwWindowShouldClose(window) == GL_TRUE)
            running = false;
    }

    glfwDestroyWindow(window);
    glfwTerminate();
}

private void update() {
    glfwPollEvents();
    level.update();
    if (level.isGameOver()) {
        level = new Level();
    }
}

private void render() {
    glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
    level.render();

    int error = glGetError();
    if (error != GL_NO_ERROR)
        System.out.println(error);

    glfwSwapBuffers(window);
}

public static void main(String[] args) {
    new Main().start();
}

}
谢谢你的帮助,另外,我是新来的堆栈溢出。如果你能把我的名声提高到15岁,我会很高兴的,这样我就可以提高其他的名声了

谢谢


-Mjl

这可能与。如错误消息所示,尝试使用
-xstartonfirsthread
运行:

java -XstartOnFirstThread Main

在Eclipse中,转到用于启动应用程序的运行配置中的Run->Run Configurations…,在Arguments选项卡下,在VM Arguments部分添加
-XstartOnFirstThread
,然后运行应用程序。

这可能与此有关。如错误消息所示,尝试使用
-xstartonfirsthread
运行:

java -XstartOnFirstThread Main

在Eclipse中,转到用于启动应用程序的运行配置中的Run->Run Configurations…,在Arguments选项卡下,在VM Arguments部分添加
-XstartOnFirstThread
,然后运行应用程序。

这可能与此有关。如错误消息所示,尝试使用
-xstartonfirsthread
运行:

java -XstartOnFirstThread Main

在Eclipse中,转到用于启动应用程序的运行配置中的Run->Run Configurations…,在Arguments选项卡下,在VM Arguments部分添加
-XstartOnFirstThread
,然后运行应用程序。

这可能与此有关。如错误消息所示,尝试使用
-xstartonfirsthread
运行:

java -XstartOnFirstThread Main

在Eclipse中,转到用于启动应用程序的运行配置中的Run->Run Configurations…,在Arguments选项卡下,在VM Arguments部分添加
-XstartOnFirstThread
,然后运行应用程序。

尝试将主方法更改为以下方法:

public static void main(String[] args) {
    new Main().run();
}

尝试将main方法更改为以下内容:

public static void main(String[] args) {
    new Main().run();
}

尝试将main方法更改为以下内容:

public static void main(String[] args) {
    new Main().run();
}

尝试将main方法更改为以下内容:

public static void main(String[] args) {
    new Main().run();
}

请更具体一点,我对Eclipse非常陌生。我该怎么办?我要改变什么?@MjlDoesProgramming更新了。请更具体一点,我对Eclipse非常陌生。我该怎么办?我要改变什么?@MjlDoesProgramming更新了。请更具体一点,我对Eclipse非常陌生。我该怎么办?我要改变什么?@MjlDoesProgramming更新了。请更具体一点,我对Eclipse非常陌生。我该怎么办?我要更改什么?@MjlDoesProgramming已更新。