【发布时间】:2021-12-12 19:47:34
【问题描述】:
我正在尝试使用 JDK 17.0.1 执行以下代码。我已确保 JDK 17 在类路径上。
这是我正在执行的代码:
import jdk.incubator.foreign.MemoryAddress;
import jdk.incubator.foreign.MemoryHandles;
import jdk.incubator.foreign.MemorySegment;
import jdk.incubator.foreign.ResourceScope;
import java.lang.invoke.VarHandle;
import java.nio.ByteOrder;
public class PanamaMain {
public static void main (String[] args) {
MemoryAddress address = MemorySegment.allocateNative(4, ResourceScope.newImplicitScope()).address();
VarHandle handle = MemoryHandles.varHandle(int.class, ByteOrder.nativeOrder());
int value = (int) handle.get(address); //This line throws the exception mentioned above.
System.out.println("Memory Value: " + value);
}
}
异常原因是:java.lang.UnsatisfiedLinkError: 'java.lang.Object java.lang.invoke.VarHandle.get(java.lang.Object[])'
我看到一些关于类似异常的回复,建议使用java.library.path 系统属性,但我收到一个错误,指出java.library.path 是无效标志。
非常感谢您在此问题上的帮助/提示!提前感谢您的宝贵时间!
【问题讨论】:
-
Please do not upload images of code/errors when asking a question.。在这种情况下,只需将整个堆栈跟踪复制粘贴到您的问题中。
标签: java memory native unsatisfiedlinkerror