0

I am facing the familiar Java error in r while loading library(xlsx) in Macos-Mojave.

I have tried reinstalling the jdk-8 and sudo R CMD javareconf as mentioned here,

  1. https://github.com/rstudio/rstudio/issues/2254
  2. rJava load error in RStudio/R after "upgrading" to OSX Yosemite

Note the library(rjava) loads fine, but fails at 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")

Can someone direct to a solution here. Thanks a lot.

Konrad Rudolph
  • 530,221
  • 131
  • 937
  • 1,214
der_radler
  • 549
  • 1
  • 6
  • 17
  • 1
    The error message is fairly explicit: It’s trying to load Java 12, and Java 12 can’t be used due to “broken JNI support”. You’ve tried reinstalling Java 8 but you apparently still have Java 12 installed in parallel next to it — unfortunately this won’t work. You might be able to set the default Java version to Java 8, but I am not aware of any way to do this on macOS. – Konrad Rudolph Jul 16 '19 at 16:43

1 Answers1

0

Based on @Konrad's answer I did the following to get rid of all versions except Java 8.

Check for existing versions

/usr/libexec/java_home -V

Navigate to that version of Java that needs to be uninstalled.

cd /Library/Java/JavaVirtualMachines

In the JavaVirtualMachines path, type in ls to see what versions of Java are existing there. It showed up as,

jdk-11.0.2.jdk      jdk-12.0.1.jdk      jdk1.8.0_211.jdk

removed all except 8.

sudo rm -rf jdk-11.0.2.jdk (and others)

library(xlsx) works now.

der_radler
  • 549
  • 1
  • 6
  • 17