JNA - JVM 致命错误 - XGetInputFocus - Ubuntu
JNA - JVM Fatal Error - XGetInputFocus - Ubuntu
OS: Ubuntu 16.04
JNA: 4.2.2
JDK: 1.8.0u111
我正在尝试在 Ubuntu 上的 JavaFX 应用程序 运行 中使用 JNA 检索当前聚焦的 window。
为了实现我的目标,我正在使用 X11 api,更准确地说,函数 XGetInputFocus
是这样的:
if (Platform.isLinux()) {
System.err.println("Linux platform");
final X11 x11 = X11.INSTANCE;
final XLib xlib = XLib.INSTANCE;
X11.Display display = x11.XOpenDisplay(null);
//X11.Window window = new X11.Window();
X11.WindowByReference winRef = new X11.WindowByReference();
Pointer pointer = Pointer.NULL;
xlib.XGetInputFocus(display, winRef, pointer);
/*X11.XTextProperty name = new X11.XTextProperty();
x11.XGetWMName(display, window, name);
System.out.println(name.toString());*/
}
-
public interface XLib extends X11 {
XLib INSTANCE = (XLib) Native.loadLibrary("X11", XLib.class);
//void XGetInputFocus(X11.Display display, X11.Window focus_return, Pointer revert_to_return);
void XGetInputFocus(X11.Display display, X11.WindowByReference focus_return, Pointer revert_to_return);
}
不幸的是,我得到了以下异常,我尝试了 X11.WindowByReference
和 X11.Window
有参数,但它没有改变,异常是一样的。
Linux platform
Looking in classpath from sun.misc.Launcher$AppClassLoader@73d16e93 for /com/sun/jna/linux-x86-64/libjnidispatch.so
Found library resource at jar:file:/home/puglic/eclipse/jna-4.2.2.jar!/com/sun/jna/linux-x86-64/libjnidispatch.so
Looking for library 'X11'
Adding paths from jna.library.path: null
Trying libX11.so
Found library 'X11' at libX11.so
#
# A fatal error has been detected by the Java Runtime Environment:
#
# SIGSEGV (0xb) at pc=0x00007f4063178e47, pid=21693, tid=0x00007f405423a700
#
# JRE version: Java(TM) SE Runtime Environment (8.0_111-b14) (build 1.8.0_111-b14)
# Java VM: Java HotSpot(TM) 64-Bit Server VM (25.111-b14 mixed mode linux-amd64 compressed oops)
# Problematic frame:
# C [libX11.so.6+0x22e47] XGetInputFocus+0x57
此外,它会生成一个名为 hs_err_pid21693.log
的巨大错误文件。我们在哪里可以找到这种线:
...
Internal exceptions (10 events):
Event: 0,223 Thread 0x00007f213000a000 Exception <a 'java/lang/NoSuchFieldError': method resolution failed> (0x00000000d7b0ded8) thrown at [/HUDSON3/workspace/8-2-build-linux-amd64/jdk8u111/7883/hotspot/src/share/vm/prims/methodHandles.cpp, line 1146]
Event: 0,262 Thread 0x00007f213000a000 Exception <a 'java/security/PrivilegedActionException'> (0x00000000d7b98008) thrown at [/HUDSON3/workspace/8-2-build-linux-amd64/jdk8u111/7883/hotspot/src/share/vm/prims/jvm.cpp, line 1386]
Event: 0,262 Thread 0x00007f213000a000 Exception <a 'java/security/PrivilegedActionException'> (0x00000000d7b98218) thrown at [/HUDSON3/workspace/8-2-build-linux-amd64/jdk8u111/7883/hotspot/src/share/vm/prims/jvm.cpp, line 1386]
Event: 0,263 Thread 0x00007f213000a000 Exception <a 'java/security/PrivilegedActionException'> (0x00000000d7b9a7e8) thrown at [/HUDSON3/workspace/8-2-build-linux-amd64/jdk8u111/7883/hotspot/src/share/vm/prims/jvm.cpp, line 1386]
Event: 0,263 Thread 0x00007f213000a000 Exception <a 'java/security/PrivilegedActionException'> (0x00000000d7b9a9f8) thrown at [/HUDSON3/workspace/8-2-build-linux-amd64/jdk8u111/7883/hotspot/src/share/vm/prims/jvm.cpp, line 1386]
Event: 0,263 Thread 0x00007f213000a000 Exception <a 'java/lang/NullPointerException'> (0x00000000d7b9afd0) thrown at [/HUDSON3/workspace/8-2-build-linux-amd64/jdk8u111/7883/hotspot/src/share/vm/interpreter/linkResolver.cpp, line 1178]
Event: 0,621 Thread 0x00007f21302c1800 Exception <a 'java/lang/NullPointerException'> (0x00000000d8349f68) thrown at [/HUDSON3/workspace/8-2-build-linux-amd64/jdk8u111/7883/hotspot/src/share/vm/interpreter/linkResolver.cpp, line 1178]
Event: 0,621 Thread 0x00007f21302c1800 Exception <a 'java/lang/NullPointerException'> (0x00000000d8349f68) thrown at [/HUDSON3/workspace/8-2-build-linux-amd64/jdk8u111/7883/hotspot/src/share/vm/prims/jvm.cpp, line 1390]
Event: 0,871 Thread 0x00007f21302c1800 Exception <a 'java/io/FileNotFoundException'> (0x00000000d87dc6d8) thrown at [/HUDSON3/workspace/8-2-build-linux-amd64/jdk8u111/7883/hotspot/src/share/vm/prims/jni.cpp, line 709]
Event: 1,041 Thread 0x00007f21302c1800 Implicit null exception at 0x00007f212120d176 to 0x00007f212120d531
...
我认为 XGetInputFocus
不会让您选择将 NULL 作为最后一个参数传递。您需要传入有效内存位置的地址,函数可以在其中写入其 revert_to
"return" 值。
您应该使用 non-null IntByReference
对象而不是 NULL。
OS: Ubuntu 16.04
JNA: 4.2.2
JDK: 1.8.0u111
我正在尝试在 Ubuntu 上的 JavaFX 应用程序 运行 中使用 JNA 检索当前聚焦的 window。
为了实现我的目标,我正在使用 X11 api,更准确地说,函数 XGetInputFocus
是这样的:
if (Platform.isLinux()) {
System.err.println("Linux platform");
final X11 x11 = X11.INSTANCE;
final XLib xlib = XLib.INSTANCE;
X11.Display display = x11.XOpenDisplay(null);
//X11.Window window = new X11.Window();
X11.WindowByReference winRef = new X11.WindowByReference();
Pointer pointer = Pointer.NULL;
xlib.XGetInputFocus(display, winRef, pointer);
/*X11.XTextProperty name = new X11.XTextProperty();
x11.XGetWMName(display, window, name);
System.out.println(name.toString());*/
}
-
public interface XLib extends X11 {
XLib INSTANCE = (XLib) Native.loadLibrary("X11", XLib.class);
//void XGetInputFocus(X11.Display display, X11.Window focus_return, Pointer revert_to_return);
void XGetInputFocus(X11.Display display, X11.WindowByReference focus_return, Pointer revert_to_return);
}
不幸的是,我得到了以下异常,我尝试了 X11.WindowByReference
和 X11.Window
有参数,但它没有改变,异常是一样的。
Linux platform
Looking in classpath from sun.misc.Launcher$AppClassLoader@73d16e93 for /com/sun/jna/linux-x86-64/libjnidispatch.so
Found library resource at jar:file:/home/puglic/eclipse/jna-4.2.2.jar!/com/sun/jna/linux-x86-64/libjnidispatch.so
Looking for library 'X11'
Adding paths from jna.library.path: null
Trying libX11.so
Found library 'X11' at libX11.so
#
# A fatal error has been detected by the Java Runtime Environment:
#
# SIGSEGV (0xb) at pc=0x00007f4063178e47, pid=21693, tid=0x00007f405423a700
#
# JRE version: Java(TM) SE Runtime Environment (8.0_111-b14) (build 1.8.0_111-b14)
# Java VM: Java HotSpot(TM) 64-Bit Server VM (25.111-b14 mixed mode linux-amd64 compressed oops)
# Problematic frame:
# C [libX11.so.6+0x22e47] XGetInputFocus+0x57
此外,它会生成一个名为 hs_err_pid21693.log
的巨大错误文件。我们在哪里可以找到这种线:
...
Internal exceptions (10 events):
Event: 0,223 Thread 0x00007f213000a000 Exception <a 'java/lang/NoSuchFieldError': method resolution failed> (0x00000000d7b0ded8) thrown at [/HUDSON3/workspace/8-2-build-linux-amd64/jdk8u111/7883/hotspot/src/share/vm/prims/methodHandles.cpp, line 1146]
Event: 0,262 Thread 0x00007f213000a000 Exception <a 'java/security/PrivilegedActionException'> (0x00000000d7b98008) thrown at [/HUDSON3/workspace/8-2-build-linux-amd64/jdk8u111/7883/hotspot/src/share/vm/prims/jvm.cpp, line 1386]
Event: 0,262 Thread 0x00007f213000a000 Exception <a 'java/security/PrivilegedActionException'> (0x00000000d7b98218) thrown at [/HUDSON3/workspace/8-2-build-linux-amd64/jdk8u111/7883/hotspot/src/share/vm/prims/jvm.cpp, line 1386]
Event: 0,263 Thread 0x00007f213000a000 Exception <a 'java/security/PrivilegedActionException'> (0x00000000d7b9a7e8) thrown at [/HUDSON3/workspace/8-2-build-linux-amd64/jdk8u111/7883/hotspot/src/share/vm/prims/jvm.cpp, line 1386]
Event: 0,263 Thread 0x00007f213000a000 Exception <a 'java/security/PrivilegedActionException'> (0x00000000d7b9a9f8) thrown at [/HUDSON3/workspace/8-2-build-linux-amd64/jdk8u111/7883/hotspot/src/share/vm/prims/jvm.cpp, line 1386]
Event: 0,263 Thread 0x00007f213000a000 Exception <a 'java/lang/NullPointerException'> (0x00000000d7b9afd0) thrown at [/HUDSON3/workspace/8-2-build-linux-amd64/jdk8u111/7883/hotspot/src/share/vm/interpreter/linkResolver.cpp, line 1178]
Event: 0,621 Thread 0x00007f21302c1800 Exception <a 'java/lang/NullPointerException'> (0x00000000d8349f68) thrown at [/HUDSON3/workspace/8-2-build-linux-amd64/jdk8u111/7883/hotspot/src/share/vm/interpreter/linkResolver.cpp, line 1178]
Event: 0,621 Thread 0x00007f21302c1800 Exception <a 'java/lang/NullPointerException'> (0x00000000d8349f68) thrown at [/HUDSON3/workspace/8-2-build-linux-amd64/jdk8u111/7883/hotspot/src/share/vm/prims/jvm.cpp, line 1390]
Event: 0,871 Thread 0x00007f21302c1800 Exception <a 'java/io/FileNotFoundException'> (0x00000000d87dc6d8) thrown at [/HUDSON3/workspace/8-2-build-linux-amd64/jdk8u111/7883/hotspot/src/share/vm/prims/jni.cpp, line 709]
Event: 1,041 Thread 0x00007f21302c1800 Implicit null exception at 0x00007f212120d176 to 0x00007f212120d531
...
我认为 XGetInputFocus
不会让您选择将 NULL 作为最后一个参数传递。您需要传入有效内存位置的地址,函数可以在其中写入其 revert_to
"return" 值。
您应该使用 non-null IntByReference
对象而不是 NULL。