在Macos-Mojave中加载library(xlsx)
时,我在r中遇到了熟悉的Java错误。
我已尝试按照此处所述重新安装jdk-8和sudo R CMD javareconf
请注意,library(rjava)
加载正常,但在library(xlsx)
失败
WARNING: Initial Java 12 release has broken JNI support and does NOT work. Use stable Java 11 (or watch for 12u if avaiable).
ERROR: Java exception occurred during rJava bootstrap - see stderr for Java stack trace.
Exception in thread "main" java.lang.NullPointerException
at java.base/jdk.internal.reflect.Reflection.verifyMemberAccess(Reflection.java:130)
at java.base/java.lang.reflect.AccessibleObject.slowVerifyAccess(AccessibleObject.java:673)
at java.base/java.lang.reflect.AccessibleObject.verifyAccess(AccessibleObject.java:666)
at java.base/java.lang.reflect.AccessibleObject.checkAccess(AccessibleObject.java:638)
at java.base/java.lang.reflect.Field.checkAccess(Field.java:1075)
at java.base/java.lang.reflect.Field.get(Field.java:416)
Error: package or namespace load failed for ‘xlsx’:
.onLoad failed in loadNamespace() for 'xlsx', details:
call: .jcheck(silent = FALSE)
error: java.lang.NullPointerException.jcall(f, "Ljava/lang/Object;", "get", .jcast(ic, "java/lang/Object"))new("jobjRef", jobj = <pointer: 0x11d737c38>, jclass = "java/lang/NullPointerException")
有人可以在这里直接找到解决方案。非常感谢。
答案 0 :(得分:0)
根据@Konrad的回答,我做了以下操作以摆脱Java 8以外的所有版本。
/usr/libexec/java_home -V
cd /Library/Java/JavaVirtualMachines
在JavaVirtualMachines路径中,输入ls
,以查看那里存在哪些Java版本。它显示为
jdk-11.0.2.jdk jdk-12.0.1.jdk jdk1.8.0_211.jdk
sudo rm -rf jdk-11.0.2.jdk (and others)
library(xlsx)
现在可以使用。