(已解决)MAC JAVA错误:Cocoa AWT: Not running on AppKit thread 0 when expected

简介: (已解决)MAC JAVA错误:Cocoa AWT: Not running on AppKit thread 0 when expected

解决办法:


参考:https://quantum6.blog.csdn.net/article/details/123204929


 代码功能:在MAC上,JAVA调用本地函数,产生一个SDL_Window,就崩溃。具体错误:


2022-02-25 09:16:25.302 java[547:10409] Cocoa AWT: Not running on AppKit thread 0 when expected. (
  0   libawt_lwawt.dylib                  0x000000010eaacb88 -[AWTWindow windowDidResignKey:] + 43
  1   CoreFoundation                      0x00007fff582541ac __CFNOTIFICATIONCENTER_IS_CALLING_OUT_TO_AN_OBSERVER__ + 12
  2   CoreFoundation                      0x00007fff5825409a _CFXRegistrationPost + 442
  3   CoreFoundation                      0x00007fff58253de2 ___CFXNotificationPost_block_invoke + 50
  4   CoreFoundation                      0x00007fff58212972 -[_CFXNotificationRegistrar find:object:observer:enumerator:] + 1826
  5   CoreFoundation                      0x00007fff58211a0c _CFXNotificationPost + 652
  6   Foundation                          0x00007fff5a2ea477 -[NSNotificationCenter postNotificationName:object:userInfo:] + 66
  7   AppKit                              0x00007fff55a2cc89 -[NSWindow resignKeyWindow] + 867
  8   AppKit                              0x00007fff55973888 -[NSWindow _changeKeyAndMainLimitedOK:] + 847
  9   AppKit                              0x00007fff55a20e9a -[NSWindow _makeKeyRegardlessOfVisibility] + 108
  10  AppKit                              0x00007fff559768f4 NSPerformVisuallyAtomicChange + 146
  11  AppKit                              0x00007fff55a20dd1 -[NSWindow makeKeyAndOrderFront:] + 90
  12  libSDL2-2.0.0.dylib                 0x000000019893b1b9 Cocoa_ShowWindow + 89
  13  libSDL2-2.0.0.dylib                 0x000000019890d3ba SDL_ShowWindow_REAL + 90
  14  libtsplayercore.dylib               0x0000000199133172 initPlayerCore + 994
  15  libtsplayercore.dylib               0x000000019913bdf2 PlayerCore_CreateWithSize + 290
  16  libtsplayercore.dylib               0x000000019913c9c2 Java_com_ts_apps_system_TPlayerCore_createWithSize + 130
  17  ???                                 0x00000001117f2087 0x0 + 4588511367
)
2022-02-25 09:16:25.302 java[547:10409]  Please file a bug report at http://java.net/jira/browse/MACOSX_PORT with this message and a reproducible test case.
2022-02-25 09:16:25.303 java[547:10409] Cocoa AWT: Not running on AppKit thread 0 when expected. (
  0   libawt_lwawt.dylib                  0x000000010eaabdcb -[AWTWindow orderChildWindows:] + 52
  1   CoreFoundation                      0x00007fff582541ac __CFNOTIFICATIONCENTER_IS_CALLING_OUT_TO_AN_OBSERVER__ + 12
  2   CoreFoundation                      0x00007fff5825409a _CFXRegistrationPost + 442
  3   CoreFoundation                      0x00007fff58253de2 ___CFXNotificationPost_block_invoke + 50
  4   CoreFoundation                      0x00007fff58212972 -[_CFXNotificationRegistrar find:object:observer:enumerator:] + 1826
  5   CoreFoundation                      0x00007fff58211a0c _CFXNotificationPost + 652
  6   Foundation                          0x00007fff5a2ea477 -[NSNotificationCenter postNotificationName:object:userInfo:] + 66
  7   AppKit                              0x00007fff55a2cc89 -[NSWindow resignKeyWindow] + 867
  8   AppKit                              0x00007fff55973888 -[NSWindow _changeKeyAndMainLimitedOK:] + 847
  9   AppKit                              0x00007fff55a20e9a -[NSWindow _makeKeyRegardlessOfVisibility] + 108
  10  AppKit                              0x00007fff559768f4 NSPerformVisuallyAtomicChange + 146
  11  AppKit                              0x00007fff55a20dd1 -[NSWindow makeKeyAndOrderFront:] + 90
  12  libSDL2-2.0.0.dylib                 0x000000019893b1b9 Cocoa_ShowWindow + 89
  13  libSDL2-2.0.0.dylib                 0x000000019890d3ba SDL_ShowWindow_REAL + 90
  14  libtsplayercore.dylib               0x0000000199133172 initPlayerCore + 994
  15  libtsplayercore.dylib               0x000000019913bdf2 PlayerCore_CreateWithSize + 290
  16  libtsplayercore.dylib               0x000000019913c9c2 Java_com_ts_apps_system_TPlayerCore_createWithSize + 130
  17  ???                                 0x00000001117f2087 0x0 + 4588511367
)
2022-02-25 09:16:25.303 java[547:10409]  Please file a bug report at http://java.net/jira/browse/MACOSX_PORT with this message and a reproducible test case.
2022-02-25 09:16:25.303 java[547:10409] Cocoa AWT: Not running on AppKit thread 0 when expected. (
  0   libosxapp.dylib                     0x000000010eb82144 +[ThreadUtilities getJNIEnv] + 37
  1   libawt_lwawt.dylib                  0x000000010eaabbcc -[AWTWindow isBlocked] + 37
  2   libawt_lwawt.dylib                  0x000000010eaabe1c -[AWTWindow orderChildWindows:] + 133
  3   CoreFoundation                      0x00007fff582541ac __CFNOTIFICATIONCENTER_IS_CALLING_OUT_TO_AN_OBSERVER__ + 12
  4   CoreFoundation                      0x00007fff5825409a _CFXRegistrationPost + 442
  5   CoreFoundation                      0x00007fff58253de2 ___CFXNotificationPost_block_invoke + 50
  6   CoreFoundation                      0x00007fff58212972 -[_CFXNotificationRegistrar find:object:observer:enumerator:] + 1826
  7   CoreFoundation                      0x00007fff58211a0c _CFXNotificationPost + 652
  8   Foundation                          0x00007fff5a2ea477 -[NSNotificationCenter postNotificationName:object:userInfo:] + 66
  9   AppKit                              0x00007fff55a2cc89 -[NSWindow resignKeyWindow] + 867
  10  AppKit                              0x00007fff55973888 -[NSWindow _changeKeyAndMainLimitedOK:] + 847
  11  AppKit                              0x00007fff55a20e9a -[NSWindow _makeKeyRegardlessOfVisibility] + 108
  12  AppKit                              0x00007fff559768f4 NSPerformVisuallyAtomicChange + 146
  13  AppKit                              0x00007fff55a20dd1 -[NSWindow makeKeyAndOrderFront:] + 90
  14  libSDL2-2.0.0.dylib                 0x000000019893b1b9 Cocoa_ShowWindow + 89
  15  libSDL2-2.0.0.dylib                 0x000000019890d3ba SDL_ShowWindow_REAL + 90
  16  libtsplayercore.dylib               0x0000000199133172 initPlayerCore + 994
  17  libtsplayercore.dylib               0x000000019913bdf2 PlayerCore_CreateWithSize + 290
  18  libtsplayercore.dylib               0x000000019913c9c2 Java_com_ts_apps_system_TPlayerCore_createWithSize + 130
  19  ???                                 0x00000001117f2087 0x0 + 4588511367
)
2022-02-25 09:16:25.303 java[547:10409]  Please file a bug report at http://java.net/jira/browse/MACOSX_PORT with this message and a reproducible test case.
2022-02-25 09:16:25.306 java[547:10409] Apple AWT Internal Exception: java.lang.StackOverflowError
  at com.ts.apps.system.TPlayerCore.createWithSize(Native Method)
  at com.ts.apps.system.TPlayerCoreFrame$1.run(TPlayerCoreFrame.java:614)
  at java.lang.Thread.run(Thread.java:748)
2022-02-25 09:16:25.306 java[547:10409] *** Terminating app due to uncaught exception 'JavaNativeException', reason: 'Internal JNF Error: failed calling Throwable.toString()'
*** First throw call stack:
(
  0   CoreFoundation                      0x00007fff582c332b __exceptionPreprocess + 171
  1   libobjc.A.dylib                     0x00007fff7ec51942 objc_exception_throw + 48
  2   CoreFoundation                      0x00007fff582c3279 -[NSException raise] + 9
  3   JavaNativeFoundation                0x00007fff5bdb08a0 JNFCallBooleanMethod + 218
  4   libawt_lwawt.dylib                  0x000000010eaabc08 -[AWTWindow isBlocked] + 97
  5   libawt_lwawt.dylib                  0x000000010eaabe1c -[AWTWindow orderChildWindows:] + 133
  6   CoreFoundation                      0x00007fff582541ac __CFNOTIFICATIONCENTER_IS_CALLING_OUT_TO_AN_OBSERVER__ + 12
  7   CoreFoundation                      0x00007fff5825409a _CFXRegistrationPost + 442
  8   CoreFoundation                      0x00007fff58253de2 ___CFXNotificationPost_block_invoke + 50
  9   CoreFoundation                      0x00007fff58212972 -[_CFXNotificationRegistrar find:object:observer:enumerator:] + 1826
  10  CoreFoundation                      0x00007fff58211a0c _CFXNotificationPost + 652
  11  Foundation                          0x00007fff5a2ea477 -[NSNotificationCenter postNotificationName:object:userInfo:] + 66
  12  AppKit                              0x00007fff55a2cc89 -[NSWindow resignKeyWindow] + 867
  13  AppKit                              0x00007fff55973888 -[NSWindow _changeKeyAndMainLimitedOK:] + 847
  14  AppKit                              0x00007fff55a20e9a -[NSWindow _makeKeyRegardlessOfVisibility] + 108
  15  AppKit                              0x00007fff559768f4 NSPerformVisuallyAtomicChange + 146
  16  AppKit                              0x00007fff55a20dd1 -[NSWindow makeKeyAndOrderFront:] + 90
  17  libSDL2-2.0.0.dylib                 0x000000019893b1b9 Cocoa_ShowWindow + 89
  18  libSDL2-2.0.0.dylib                 0x000000019890d3ba SDL_ShowWindow_REAL + 90
  19  libtsplayercore.dylib               0x0000000199133172 initPlayerCore + 994
  20  libtsplayercore.dylib               0x000000019913bdf2 PlayerCore_CreateWithSize + 290
  21  libtsplayercore.dylib               0x000000019913c9c2 Java_com_ts_apps_system_TPlayerCore_createWithSize + 130
  22  ???                                 0x00000001117f2087 0x0 + 4588511367
)
libc++abi.dylib: terminating with uncaught exception of type JNFException

尝试解决一:使用Thread.join(),失败

尝试解决二:使用invokeLater(),失败

目录
相关文章
|
4月前
|
Java 开发者
Java面试题:请解释内存泄漏的原因,并说明如何使用Thread类和ExecutorService实现多线程编程,请解释CountDownLatch和CyclicBarrier在并发编程中的用途和区别
Java面试题:请解释内存泄漏的原因,并说明如何使用Thread类和ExecutorService实现多线程编程,请解释CountDownLatch和CyclicBarrier在并发编程中的用途和区别
56 0
|
3月前
|
Java 开发者
奇迹时刻!探索 Java 多线程的奇幻之旅:Thread 类和 Runnable 接口的惊人对决
【8月更文挑战第13天】Java的多线程特性能显著提升程序性能与响应性。本文通过示例代码详细解析了两种核心实现方式:Thread类与Runnable接口。Thread类适用于简单场景,直接定义线程行为;Runnable接口则更适合复杂的项目结构,尤其在需要继承其他类时,能保持代码的清晰与模块化。理解两者差异有助于开发者在实际应用中做出合理选择,构建高效稳定的多线程程序。
59 7
|
19天前
|
Java 网络安全 Maven
Exception in thread "main" java.lang.NoSuchMethodError: okhttp3.OkHttpClient$Builder.sslSocketFactory(Ljavax/net/ssl/SSLSocketFactory;Ljavax/net/ssl/X509TrustManager;)Lokhttp3/OkHttpClient$Builder; 问题处理
【10月更文挑战第26天】Exception in thread "main" java.lang.NoSuchMethodError: okhttp3.OkHttpClient$Builder.sslSocketFactory(Ljavax/net/ssl/SSLSocketFactory;Ljavax/net/ssl/X509TrustManager;)Lokhttp3/OkHttpClient$Builder; 问题处理
35 2
|
25天前
|
Java 开发者
在Java多线程编程中,创建线程的方法有两种:继承Thread类和实现Runnable接口
【10月更文挑战第20天】在Java多线程编程中,创建线程的方法有两种:继承Thread类和实现Runnable接口。本文揭示了这两种方式的微妙差异和潜在陷阱,帮助你更好地理解和选择适合项目需求的线程创建方式。
19 3
|
25天前
|
Java
在Java多线程编程中,实现Runnable接口通常优于继承Thread类
【10月更文挑战第20天】在Java多线程编程中,实现Runnable接口通常优于继承Thread类。原因包括:1) Java只支持单继承,实现接口不受此限制;2) Runnable接口便于代码复用和线程池管理;3) 分离任务与线程,提高灵活性。因此,实现Runnable接口是更佳选择。
33 2
|
25天前
|
Java
Java中多线程编程的基本概念和创建线程的两种主要方式:继承Thread类和实现Runnable接口
【10月更文挑战第20天】《JAVA多线程深度解析:线程的创建之路》介绍了Java中多线程编程的基本概念和创建线程的两种主要方式:继承Thread类和实现Runnable接口。文章详细讲解了每种方式的实现方法、优缺点及适用场景,帮助读者更好地理解和掌握多线程编程技术,为复杂任务的高效处理奠定基础。
28 2
|
25天前
|
Java 开发者
Java多线程初学者指南:介绍通过继承Thread类与实现Runnable接口两种方式创建线程的方法及其优缺点
【10月更文挑战第20天】Java多线程初学者指南:介绍通过继承Thread类与实现Runnable接口两种方式创建线程的方法及其优缺点,重点解析为何实现Runnable接口更具灵活性、资源共享及易于管理的优势。
28 1
|
2月前
|
存储 Java 程序员
优化Java多线程应用:是创建Thread对象直接调用start()方法?还是用个变量调用?
这篇文章探讨了Java中两种创建和启动线程的方法,并分析了它们的区别。作者建议直接调用 `Thread` 对象的 `start()` 方法,而非保持强引用,以避免内存泄漏、简化线程生命周期管理,并减少不必要的线程控制。文章详细解释了这种方法在使用 `ThreadLocal` 时的优势,并提供了代码示例。作者洛小豆,文章来源于稀土掘金。
|
3月前
|
Java
在 Java 中 Runnable 与 Thread 的适时运用
【8月更文挑战第22天】
23 0
|
3月前
|
Java
Exception in thread "main" java.lang.UnsatisfiedLinkError: xxx()V
Exception in thread "main" java.lang.UnsatisfiedLinkError: xxx()V
20 0