当前位置: 首页 > 知识库问答 >
问题:

线程“game”java.lang.IllegalStateException中的异常:请使用-XStartonFirstThread运行JVM

殷学
2023-03-14

线程“game”java.lang.IllegalStateException中的异常:请使用-XStartonFirstThread运行JVM。在org.lwjgl.system.macosx.eventloop.checkFirstThread(eventloop.java:20)在org.lwjgl.glfw.glfw.glfw.glfw.glfw.glfwinit(Glfw.java:428)在com.cherno.flappy.main.init(main.java:41)在com.cherno.flappy.main.run(main.java:65)在java.lang.thread.run(thread.java:745)

由该代码给出:

package com.cherno.flappy;

import static org.lwjgl.glfw.GLFW.*;

import static org.lwjgl.opengl.GL11.*;
import static org.lwjgl.system.MemoryUtil.*;

import java.nio.ByteBuffer;

import org.lwjgl.glfw.GLFWvidmode;

public class Main implements Runnable {


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

private boolean running = false;

private Thread thread;

/*window è un long perché lwjgl è un bindng di c in java.
 * Non esistono oggetti in c, solo id, ed ecco cosa abbiamo.
 */
private long window;

public void start() {

    running = true;
    thread = new Thread(this, "Game"); //Punto (A)
    thread.start(); //Lo start fa partire il run di sotto
}

/*Inizializzo OpenGL qui dentro
 * OpenGL gira in un thread solo!! RICORDALO
 */
private void init() {
    if (glfwInit() != GL_TRUE) {
        //Handle it
        return;
    }

    glfwWindowHint(GLFW_RESIZABLE, GL_TRUE);
    //Creo la finestra e mi faccio tornare il puntatore di C
    window = glfwCreateWindow(width, height, "Flappy", NULL, NULL);
    //Vedo se la finestra è creata
    if (window == NULL) {
        //MAke something
        return;
    }

    ByteBuffer vidmode = glfwGetVideoMode(glfwGetPrimaryMonitor());
    //Decido la posizione della finestra
    glfwSetWindowPos(window, (GLFWvidmode.width(vidmode)-width)/2, (GLFWvidmode.height(vidmode)-height)/2);
    //Setto il contesto per OpenGL
    glfwMakeContextCurrent(window);
    //Mostro la finestra
    glfwShowWindow(window);
}

public void run() {     
    init();

    while(running) {
        update();
        render();

        //Controllo se l'utente vuole uscire
        if(glfwWindowShouldClose(window) == GL_TRUE) running = false;
    }       
}

private void update() {
    glfwPollEvents();
}

private void render() {
    glfwSwapBuffers(window);
}

public static void main(String args[]) {

    new Main().start();

}
}

异常显然要求我使用-XStartonThread参数启动jvm。我在Eclipse中执行“run>run configuration>arguments tab>vm arguments”并键入“-XStartonThread”;然后单击“Run”,得到以下错误:

进程:java[569]路径:/library/java/javavirtualmachines/jdk1.8.0_51.jdk/contents/home/bin/java标识符:java版本:1.0(1.0)代码类型:X86-64(本机)父进程:eclipse[478]负责:eclipse[478]用户ID:501

日期/时间:2015-08-06 21:41:32.956+0200 OS版本:
Mac OS X 10.10.4(14E46)报告版本:11 Anonymous UUID:
CBCCB665-9B7F-C8CC-612E-828FAD3AA52D

启动后唤醒时间:1500秒

崩溃的线程:20 Java:游戏

异常类型:EXC_CRASH(SIGABRT)异常代码:
0x000000000000000000000000,0x0000000000000000

应用程序特定信息:***由于未捕获的异常'nsinternalinconsistencyexception'而终止应用程序,原因:'+[nsundomanager(NSInternal)_endtoplevelgroupings]只能在主线程上安全调用。‘以未捕获的类型为NSException abort()的异常终止

线程1:0 libsystem_kernel.dylib 0x00007fff8a578136__psynch_cvwait+10 1 com.apple.foundation 0x00007fff8e28df08-[NSCondition wait]+237 2 com.apple.foundation 0x00007fff8e27ed9e-[nsobject(NSThreadPerformAdditions)performselector:onthread:WaitUntildone:modes:]+823 3
com.apple.foundation 00000107D7D7B5 JVMInit+251 5 java
0x0000000107D7ACF1 JLI_Launch+4837 6 java
0x0000000107D804C0 main+101 7 java
0x0000000107D7E0F5 apple_main+92 8 libsystem_pthread.dylib
0x00007FF8A4B8268_pthread_body+131 9 libsystem_pthread.dylib
0x00007FF8A4B8268E5_pthread_start+176 10 4B641D thread_start+13

线程2::Dispatch queue:com.apple.libdispatch-manager 0
libsystem_kernel.dylib 0x00007fff8a579232 kevent64+101
libdispatch.dylib 0x00007fff8f674a6a_dispatch_mgr_thread+52

线程3:0 libsystem_kernel.dylib 0x00007fff8a578136__psynch_cvwait+10 1 libjvm.dylib 0x0000000108c6a7b4 OS::platformevent::park()+192 libjvm.dylib
0x0000000108c48504 ParkCommon(Parkevent*,long)+42 3 libjvm.dylib 0x0000000108dylib monitor::iwait(Thread*,long)+168 4
libjvm.dylib 5 libjvm.dylib
0x0000000108a6b1a6 gctaskmanager::get_task(无符号int)+56 6
libjvm.dylib 0x0000000108a6bf85 gctaskthread::run()+349 7 libjvm.dylib 0x0000000108c6e99e java_start(Thread*)+246 8 libsystem_pthread.dylib
0x00007fff8a4b8268_pthread_body+131 9 libsystem_pthread.dylib Start+176 10 libsystem_pthread.dylib
0x00007fff8a4b641d thread_start+13

线程4:0 libsystem_kernel.dylib 0x00007fff8a578136__psynch_cvwait+10 1 libjvm.dylib 0x0000000108c6a7b4 OS::platformevent::park()+192 libjvm.dylib
0x0000000108c48504 ParkCommon(Parkevent*,long)+42 3 libjvm.dylib 0x0000000108dylib monitor::iwait(Thread*,long)+168 4
libjvm.dylib 5 libjvm.dylib
0x0000000108a6b1a6 gctaskmanager::get_task(无符号int)+56 6
libjvm.dylib 0x0000000108a6bf85 gctaskthread::run()+349 7 libjvm.dylib 0x0000000108c6e99e java_start(Thread*)+246 8 libsystem_pthread.dylib
0x00007fff8a4b8268_pthread_body+131 9 libsystem_pthread.dylib Start+176 10 libsystem_pthread.dylib
0x00007fff8a4b641d thread_start+13

线程5:0 libsystem_kernel.dylib 0x00007fff8a578136__psynch_cvwait+10 1 libjvm.dylib 0x0000000108c6a7b4 OS::platformevent::park()+192 libjvm.dylib
0x0000000108c48504 ParkCommon(Parkevent*,long)+42 3 libjvm.dylib 0x0000000108dylib monitor::iwait(Thread*,long)+168 4
libjvm.dylib 5 libjvm.dylib
0x0000000108a6b1a6 gctaskmanager::get_task(无符号int)+56 6
libjvm.dylib 0x0000000108a6bf85 gctaskthread::run()+349 7 libjvm.dylib 0x0000000108c6e99e java_start(Thread*)+246 8 libsystem_pthread.dylib
0x00007fff8a4b8268_pthread_body+131 9 libsystem_pthread.dylib Start+176 10 libsystem_pthread.dylib
0x00007fff8a4b641d thread_start+13

线程6:0 libsystem_kernel.dylib 0x00007fff8a578136__psynch_cvwait+10 1 libjvm.dylib 0x0000000108c6a7b4 OS::platformevent::park()+192 libjvm.dylib
0x0000000108c48504 ParkCommon(Parkevent*,long)+42 3 libjvm.dylib 0x0000000108dylib monitor::iwait(Thread*,long)+168 4
libjvm.dylib 5 libjvm.dylib
0x0000000108a6b1a6 gctaskmanager::get_task(无符号int)+56 6
libjvm.dylib 0x0000000108a6bf85 gctaskthread::run()+349 7 libjvm.dylib 0x0000000108c6e99e java_start(Thread*)+246 8 libsystem_pthread.dylib
0x00007fff8a4b8268_pthread_body+131 9 libsystem_pthread.dylib Start+176 10 libsystem_pthread.dylib
0x00007fff8a4b641d thread_start+13

线程7:0 libsystem_kernel.dylib 0x00007fff8a578136__psynch_cvwait+10 1 libjvm.dylib 0x0000000108c6b69e OS::platformevent::park(long)+404 2
libjvm.dylib 0x0000000108c48dda monitor::iwait(Thread*,long)+168 3 libjvm.dylib
0x0000000108c48dda monitor::wait(bool,long,bool)+375 4)+444 5 libjvm.dylib 0x0000000108d942f5 vmthread::run()+121 6 libjvm.dylib
0x0000000108c6e99e java_start(Thread*)+246 7
libsystem_pthread.dylib 0x00007ffff8a4b8268_pthread_body+131 8 libsystem_pthread.dylib 0x00007fff8a4b81e5_pthread_start+176 9 libsystem_pthread.dylib

线索8::Java:引用处理程序0libsystem_kernel.dylib
0x00007FF8A578136__psynch_cvwait+101libjvm.dylib
0x0000000108C6A7B4OS::PlatformEvent::Park()+192libjvm.dylib
0x0000000108C6295ObjectMonitor::Wait(long,bool,thread*)+7483
libjvm.dylib0x0000000108dhandle,long,thread*)A16 JVM_MonitorWait+156 5???
0x000000010977E954 0+4453820756 6???
0x0000000109770C4D 0+4453764173 7???
0x0000000109770C4D 0+4453764173 8???
0x00000001097697A7 0+4453734311 9 libjvm.dylib
0x000000010976911 ents*,thread*)+1710 10 libjvm.dylib
0x0000000108AE0970 javacalls::call_virtual(javavalue*,KlassHandle,symbol*,symbol*,symbol*,javacallalarguments*,thread*)+356 11 libjvm.dylib 0x0000000108AE0b1c javacalls::call_virtual(javavalue*,Handle,KlassHandle,symbol*,symbol*,thread*)+74 12_entry(javathread*,thread*)+124 13 libjvm.dylib 0x0000000108d49a6f javathread::thread_main_inner()+155 14 libjvm.dylib
0x0000000108d4b160 javathread::run()+450 15 libjvm.dylib
0x0000000108c6e99e java_start(thread*)+246 16 libsystem_pthread.dylib 0x00007fff8a4b8268_pthread_body+131 17+176 18 libsystem_pthread.dylib 0x00007fff8a4b641d thread_start+13

线程9::Java:终结器0 libsystem_kernel.dylib
0x00007fff8a578136__psynch_cvwait+10 1 libjvm.dylib
0x0000000108c6a7b4 os::platformevent::park()+192 libjvm.dylib
0x0000000108c62952 objectmonitor::wait(long,布尔,线程*)+748 3
libjvm.dylib 0x0000000108D17978 ObjectSynchronizer::Wait(句柄,长,线程*)+202 4 libjvm.dylib 0x0000000108b39a16 JVM_MonitorWait+156 5???
0x000000010977e954 0+4453820756 6???
0x0000000109770c4d 0+4453764173 7???
0x00000001097709d0+4453763536 8???
0x00000001097709d0+4453763536 9???
0x00000001097697a7 0+4453763536 34311 10 libjvm.dylib
0x0000000108AE01E2 JavaCalls::call_helper(JavaValue*,methodHandle*,javacallarguments*,thread*)+1710 11 libjvm.dylib
0x0000000108AE0970 javacalls::call_virtual(javavalue*,KlassHandle,symbol*,symbol*,symbol*,javacallarguments*,thread*)+356 12 libjvm.dylib 0x0000000108Ae0b1c javacalls::call_virtual(javavalue*,Handle,KlassHandle,symbol*,symbol*,libjvm.dylib 0x0000000108d49a6f javathread::thread_main_inner()+155 15 libjvm.dylib
0x0000000108d4b160 javathread::run()+450 16 libjvm.dylib
0x0000000108c6e99e java_start(thread*)+246 17 libsystem_pthread.dylib 0x00007fff8a4b8268_pthread_body+131 18 libsystem_pthread.dylib 00007FFF8A4B641D thread_start+13

线程10:0 libsystem_kernel.dylib 0x00007fff8a57894a__workq_kernreturn+10 1 libsystem_pthread.dylib 0x00007fff8a4b640d start_wqthread+13

线程11:0 libsystem_kernel.dylib 0x00007fff8a57894a__workq_kernreturn+10 1 libsystem_pthread.dylib 0x00007fff8a4b640d start_wqthread+13

线程12:0 libsystem_kernel.dylib 0x00007fff8a57894a__workq_kernreturn+10 1 libsystem_pthread.dylib 0x00007fff8a4b640d start_wqthread+13

线程13:0 libsystem_kernel.dylib 0x00007fff8a57894a__workq_kernreturn+10 1 libsystem_pthread.dylib 0x00007fff8a4b640d start_wqthread+13

Thread 14::Java:Signal Dispatcher 0 libsystem_kernel.dylib
0x00007FFF8A57351A semaphore_wait_trap+10 1 libjvm.dylib
0x0000000108C6CD04 check_pending_signals(bool)+128 2 libjvm.dylib 0x0000000108C69845 signal_thread_entry(javathread*,Thread*)+57 3
libjvm.dylib 0x0000000108dylib B160 javathread::run()+450 5 libjvm.dylib
0x0000000108c6e99e java_start(Thread*)+246 6
libsystem_pthread.dylib 0x00007ffff8a4b8268_pthread_body+131 7 libsystem_pthread.dylib 0x00007fff8a4b81e5_pthread_start+176 8 libsystem_pthread.dylib 0x00007fff8a4b6b641d thread_start+13

Thread 15::Java:C2 CompilerThread0 libsystem_kernel.dylib
0x00007FFF8A578136__psynch_cvwait+10 1 libjvm.dylib
0x0000000108C6b69e OS:::PlatformEvent::Park(long)+404 2
libjvm.dylib 0x0000000108C48dda Monitor::Iwait(Thread*,long)+168 3 libjvm.dylib
0x0000000108C48Faa 00000001089b24b2 compilequeue::get()+122 5 libjvm.dylib 0x00000001089b26d4 compilebroker::compiler_thread_loop()+376 libjvm.dylib
0x0000000108d49a6f javathread::thread_main_inner()+155 7
libjvm.dylib 0x0000000108d4b160 javathread::run()+450 8 libjvm.dylib 0x0000000108c6e99e 00007fff8a4b8268_pthread_body+131 10 libsystem_pthread.dylib
0x00007fff8a4b81e5_pthread_start+176 11 libsystem_pthread.dylib
0x00007fff8a4b641d thread_start+13

Thread 16::Java:C2 CompilerThread1 0 libsystem_kernel.dylib
0x00007FFF8A578136__psynch_cvwait+10 1 libjvm.dylib
0x0000000108C6b69e OS:::PlatformEvent::Park(long)+404 2
libjvm.dylib 0x0000000108C48dda Monitor::Iwait(Thread*,long)+168 3 libjvm.dylib
0x0000000108C48Faa 00000001089b24b2 compilequeue::get()+122 5 libjvm.dylib 0x00000001089b26d4 compilebroker::compiler_thread_loop()+376 libjvm.dylib
0x0000000108d49a6f javathread::thread_main_inner()+155 7
libjvm.dylib 0x0000000108d4b160 javathread::run()+450 8 libjvm.dylib 0x0000000108c6e99e 00007fff8a4b8268_pthread_body+131 10 libsystem_pthread.dylib
0x00007fff8a4b81e5_pthread_start+176 11 libsystem_pthread.dylib
0x00007fff8a4b641d thread_start+13

Thread 17::Java:C1 CompilerThread2 0 libsystem_kernel.dylib
0x00007FFF8A578136__psynch_cvwait+10 1 libjvm.dylib
0x0000000108C6b69e OS:::PlatformEvent::Park(long)+404 2
libjvm.dylib 0x0000000108C48dda Monitor::Iwait(Thread*,long)+168 3 libjvm.dylib
0x0000000108C48Faa 00000001089b24b2 compilequeue::get()+122 5 libjvm.dylib 0x00000001089b26d4 compilebroker::compiler_thread_loop()+376 libjvm.dylib
0x0000000108d49a6f javathread::thread_main_inner()+155 7
libjvm.dylib 0x0000000108d4b160 javathread::run()+450 8 libjvm.dylib 0x0000000108c6e99e 00007fff8a4b8268_pthread_body+131 10 libsystem_pthread.dylib
0x00007fff8a4b81e5_pthread_start+176 11 libsystem_pthread.dylib
0x00007fff8a4b641d thread_start+13

Thread 18::Java:Service Thread 0 libsystem_kernel.dylib
0x00007FF8A578136__psynch_cvwait+10 1 libjvm.dylib
0x0000000108C6A7B4 OS::platformevent::park()+192 libjvm.dylib
0x0000000108C48504 ParkCommon(Parkevent*,long)+42 3 libjvm.dylib 0x0000000108C48dda monitor::iwait(Thread*,long)+168 wait(bool,long,bool)+375 5 libjvm.dylib
0x0000000108cc3b36 servicethread::service_thread_entry(javathread*,Thread*)+132 6 libjvm.dylib 0x0000000108d49a6f javathread::thread_main_inner()+155 7 libjvm.dylib
0x0000000108d4b160 javathread::run()+450 8 libjvm.dylib
0x0000000108c6e99e b 0x00007FFF8A4b8268_pthread_body+131 10 libsystem_pthread.dylib 0x00007ffF8A4b81e5_pthread_start+176 11 libsystem_pthread.dylib 0x00007ffF8A4b641d thread_start+13

线程19:0 libsystem_kernel.dylib 0x00007fff8a578136__psynch_cvwait+10 1 libjvm.dylib 0x0000000108c6b69e OS::platformevent::park(long)+404 2
libjvm.dylib 0x0000000108c48dda监视器::iwait(Thread*,long)+168 3 libjvm.dylib
0x0000000108c49043监视器::wait(bool,long,bool)+375 4 const+126 5 libjvm.dylib
0x0000000108d4add5 watcherthread::run()+243 6 libjvm.dylib
0x0000000108c6e99e java_start(Thread*)+246 7
libsystem_pthread.dylib 0x00007ffff8a4b8268_pthread_body+131 8 libsystem_pthread.dylib 0x00007fff8a4b81e5_pthread_start+176 9 libsystem_pthread.dylib

线程20崩溃::java:Game 0 libsystem_kernel.dylib
0x00007fff8a578286__pthread_kill+10 1 libsystem_c.dylib
0x00007fff91eecb53 abort+129 2 libc++abi.dylib
0x00007fff8a8fda21 abort_message+257 3 libc++abi.dylib
0x00007fff8a9259d1 default_terminate_handler()+267 4 libc++abi.dylib 0x00007fff8a9230a1 std::__terminate(void()())+8 6 libc++abi.dylib
0x00007fff8a922b30__cxa_throw+121 7 libobjc.a.dylib
0x00007fff89d86898 objc_exception_throw+341 8
com.apple.coreFoundation 0x00007fff879b1a+[NSException引发:格式:参数:]+106 9 com.apple.foundation ureinmethod:object:file:lineNumber:description:]+195 10 com.apple.foundation 0x00007FFF8E29957F+[nsundomanager(NSPrivate)_endtopLevelGroupings]+156 11 com.apple.appkit 0x00007FF87F51C41-[NSApplication run]+928 12 liblwjgl.dylib 0x0000000121828A2E_glfwplatformCreateWindow+1406 13 liblwjgl.dylib 0x0000000121824d9b glfwCreateWindow+443 14???
0x000000010977e954 0+4453820756 15???
0x0000000109770760 0+4453762912 16???
0x0000000109770760+4453762912 17???
0x0000000109770760+4453764173 18???
0x0000000109770C4d 0+4453764173 18???
0x0000000109770C92 0+19???
0x00000001097697A7 0+4453734311 20 libjvm.dylib
0x0000000108AE01E2 javacalls::call_helper(JavaValue,methodHandle*,javacallarguments*,thread*)+1710 21 libjvm.dylib
0x0000000108AE0970 javacalls::call_virtual(javavalue*,KlassHandle,symbol*,symbol*,symbol*,javacallarguments*,thread*)+356 22 libjvm.dylib 0x0000000108Ae0b1c javacalls::call_virtual(javavalue*,Handle,KlassHandle,symbol*,symbol*,libjvm.dylib 0x0000000108d49a6f javathread::thread_main_inner()+155 25 libjvm.dylib
0x0000000108d4b160 javathread::run()+450 26 libjvm.dylib
0x0000000108c6e99e java_start(thread*)+246 27 libsystem_pthread.dylib 0x00007fff8a4b8268_pthread_body+131 28 libsystem_pthread.dylib 00007FFF8A4B641D thread_start+13

线程20崩溃,X86线程状态(64位):RAX:0x00000000000000000000RBX:0x0000000000000000RCX:0x00000000001217B7C58 RDX:0x0000000000000000RDI:0x000000000000RBP:0x000000001217B7C80 RSP:0x00000000617B7C58
R8:0x6E6F697470656378 R9:0x00007FF91F16D70 000206 R12:0x00000001217B7DE0 R13:0x00007FE7C0D223F0 R14:0x00000001217BA000 R15:0x00000001217B7CC0 RIP:0x00007FFF8A578286 RFL:0x0000000000000000206 CR2:0x00007FF7722BFD8逻辑CPU:0错误代码:
0x02000148陷阱号:133

共有1个答案

农飞翔
2023-03-14

似乎您正在用新的Main().start()创建另一个主类;

因为您是主要的,也许可以尝试this.start();

另外,如果这不能解决问题,请尝试创建一个包含所有线程内容的第二个类,然后在main中执行:new mythreadclass.start();

 类似资料:
  • 从终端执行jar时,我得到以下信息: 我搜索了他的错误,发现了一些相同的执行输出错误,但没有解决我的情况。 下面详细介绍了文件的位置、清单内容、所采取的终端步骤以及所涉及的两个类文件的代码内容。 文件位置 > SWT库 舱单 班级 普通人。jar(参见下面的创建): Manifest.txt内容: 终端动作 > 目录更改 . jar创建 舱单检查 普通人。jar执行 密码 用户nterface.c

  • 试图使用Appium(Java)在android设备上自动化本机应用程序,但遇到了以下错误: 线程"main"中的异常java.lang.NoClassDefFoundError: org/openqa/selenium/远程/内部/JsonToWebElementConverter atwibu.main(wibu.java:21) 原因:java.lang.ClassNotFoundExcep

  • 我很难理解这个代码有什么问题。Dr.Java一切都很好,但是在另一个名为edhesive的代码运行平台上(我就是在这个平台上被分配这个项目的),它给我一个错误。我已经检查了所有我认为出错的地方,但仍然不知道哪里出了问题。 在edhesive上运行后,我得到了这个错误 有人能帮帮我吗?

  • 问题内容: 我已经在eclipse中尝试过此代码: 执行时出现此错误: 如何在ubuntu中设置geckodriver位置? 问题答案: 当您在指定 GeckoDriver 的绝对路径时使用 基于Linux的系统 时,必须修剪扩展部分,即part,如下所示: __ 更新资料 如您仍在看到错误,请确保: GeckoDriver 位于指定的位置。 GeckoDriver 具有非root用户的可执行权限

  • 我已经编写了一段代码,其中我制作了一个接口和一个实现该接口的类。现在,当我运行代码时,我给了我自己2个选项,即1输入字符串,2退出。现在,当我运行代码时,如果我选择1,它会让我放入字符串,但在此之后,当我按0时,它会给我错误:Exception in thread“main”java.lang。有人能帮我找出我在这里遗漏了什么吗?下面是代码: StackTrace: 线程“main”java.la