Java error in MacOS Mojavew when loading a package - r

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,
https://github.com/rstudio/rstudio/issues/2254
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.

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.

Related

"Java exception occurred during rJava bootstrap" when trying to use tabulizer

I'm running Mac OS 10.13.6, and using RStudio 1.1.8, R 3.5.3, Java 11. In case hardware might matter, I'm using a 2013 MacBook Air.
I'm trying to run the extract_table function from the r tabulizer package on the Correlates of War World Religion Codebook, available here. I seem to be getting stuck because of an error with rJava. The rJava library seems to load in RStudio just fine, but when I run the following line:
lst <- tabulizer::extract_tables("/Users/[me]/Downloads/wrp-codebook-bibliography.pdf", encoding="UTF-8")
or try to load the tabulizer library, I receive the following error:
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: .onLoad failed in loadNamespace() for 'tabulizerjars', details:
call: .jcheck(silent = FALSE)
error: java.lang.NullPointerException.jcall(f, "Ljava/lang/Object;", "get", .jcast(ic, "java/lang/Object"))new("jobjRef", jobj = <pointer: 0x10caa0870>, jclass = "java/lang/NullPointerException")
EDIT: the below section has been update for clarity based on a comment received.
At first I thought it was that I needed to switch from Java 12 to Java 11, so I found a helpful post on SO and used the following commands to make that switch, with no instances of RStudio or R running while I did it:
MacBook-Air:~ $ /usr/libexec/java_home -V
Matching Java Virtual Machines (2):
12, x86_64: "Java SE 12" /Library/Java/JavaVirtualMachines/jdk-12.jdk/Contents/Home
11.0.2, x86_64: "Java SE 11.0.2" /Library/Java/JavaVirtualMachines/jdk-11.0.2.jdk/Contents/Home
/Library/Java/JavaVirtualMachines/jdk-12.jdk/Contents/Home
MacBook-Air:~ $ export JAVA_HOME=`/usr/libexec/java_home -v 1.6.0_65-b14-462`
The problem has persisted since them and when I double-check my version of Java in the terminal, I get this:
MacBook-Air:~ $ java -version
java version "11.0.2" 2019-01-15 LTS
Java(TM) SE Runtime Environment 18.9 (build 11.0.2+9-LTS)
Java HotSpot(TM) 64-Bit Server VM 18.9 (build 11.0.2+9-LTS, mixed mode)
So it looks to me like I'm running 11.
However, I also still have 12 installed:
MacBook-Air:~ $ /usr/libexec/java_home -V
Matching Java Virtual Machines (2):
12, x86_64: "Java SE 12" /Library/Java/JavaVirtualMachines/jdk-12.jdk/Contents/Home
11.0.2, x86_64: "Java SE 11.0.2" /Library/Java/JavaVirtualMachines/jdk-11.0.2.jdk/Contents/Home
I'm not sure if R is looking at version 12 instead, or how to redirect it, or if there is another issue here all together. Unfortunately, I wasn't able to find anything on google or SO about this error specifically in the context of R and rJava.
Please let me know if I can provide any additional information.
Thanks!
Navigate to /Library/Java/JavaVirtualMachines and remove JDK 12
Reinstall JDK 11.
sudo R CMD javareconf in the terminal.
I re-installed rJava and it worked!
Using: install.packages("rjava")

RGDAL installation error: libnetcdf.so.6: cannot open shared object file: No such file or directory

I run RStudio Server on ubuntu 14.04. When trying to install the rgdal package I get the following error message:
Error in dyn.load(file, DLLpath = DLLpath, ...) :
unable to load shared object '/home/admin2/R/x86_64-pc-linux-gnu- library/2.14/rgdal/libs/rgdal.so':
libnetcdf.so.6: cannot open shared object file: No such file or directory
Error: loading failed
Execution halted
I upgraded RStudio Server, R-Core and all Ubuntu packages to their latest versions but no success. I also tried apt-get install lib32stdc++6 as suggested here, but also no changes. I think it is a problem specific to GDAL and the indexing of shared libraries in unix. Can anyone help please?
Ok I got it done removing Gdal completly, compiling it from source again and setting library paths correctly as described here. Later adding /usr/local/lib/ to /etc/ld.so.conf and run sudo ldconfig as described here.

R: rJava package fails to load

I've installed the rJava pack successfully. However, when I run the command library(rJava), I get the following error.
> library(rJava) Error : .onLoad failed in loadNamespace() for 'rJava', details: call: fun(libname, pkgname) error: JAVA_HOME
cannot be determined from the Registry Error: package or namespace
load failed for ‘rJava’
How can I solve this issue?
I had this problem running XLConnect as well. It turned out that my instance of R was unable to see the Jave Virtual Machine on my 64 bit Windows computer at work. I simply found the 64 bit version of my jvm.dll file in the folder where it lives.
You can just at the path to that .dll file to your library or require() function and it should undo the madness, although, in my case, I had to update Java completely because it was too old and set this at the beginning of my script to point to the JAVA home.
Sys.setenv(JAVA_HOME="yourpathhere")
See if that works.

Problems loading rJava Package on Win7

I have installed the latest versions of R (2.15.2) and Java (7.11), and through RStudio (0.97.310) I am trying to load the rJava package. It seemed to install properly, but when I call library(rJava) I get the following error:
Error : .onLoad failed in loadNamespace() for 'rJava', details:
call: stop("No CurrentVersion entry in '", key, "'!
Try re-installing Java and make sure R and Java have matching architectures.")
error: object 'key' not found
Error: package/namespace load failed for ‘rJava’
The documentation for rJava makes reference to Java 1.5+, so I am wondering if I need to install an ancient version of Java to resolve this problem. Any help would be much appreciated!
Ok, I figured it out. Guess I should have read the release notes on the rJava development website. I had installed Java, but not the JDK. Once I installed that, everything worked fine.
I had this problem and solved it by downloading and installing Java 64-bit (which you should probably choose if you have a modern computer) from the Java download site.

Problems installing rjags and JAGS on Mac OsX 10.5.8

I am having issues getting rjags the R package for R to call JAGS (Just Another Gibbs Sampler http://www-ice.iarc.fr/~martyn/software/jags/ ).
I am running Mac Os X. 10.5.8 Leopard and using R64 2.12.1. I compiled JAGS from the command line. Then I installed rjags in the R command line.
install.packages(rjags)
When I try to call rjags within R, I get the following error.
> library(rjags)
Error : .onLoad failed in loadNamespace() for 'rjags', details:
call: dyn.load(file, DLLpath = DLLpath, ...)
error: unable to load shared object '/Library/Frameworks/R.framework/Versions/2.12/Resources /library/rjags/libs/x86_64/rjags.so':
dlopen(/Library/Frameworks/R.framework/Versions/2.12/Resources/library/rjags/libs/x86_64/rjags.so, 10): Library not loaded: /usr/local/lib/libjags.2.dylib
Referenced from: /Library/Frameworks/R.framework/Versions/2.12/Resources/library/rjags/libs/x86_64/rjags.so
Reason: no suitable image found. Did find:
/usr/local/lib/libjags.2.dylib: mach-o, but wrong architecture
/usr/local/lib/libjags.2.dylib: mach-o, but wrong architecture
Error: package/namespace load failed for 'rjags'
I am guessing there is some issue with rjags referencing an unknown file in the library, but I am not sure. I am a fairly novice at the command line and messing around with directories, so any help would be much appreciated.
I found (after downloading and installing the dmg from SourceForge) that the following commands worked for me:
wget http://cran.r-project.org/src/contrib/rjags_2.2.0-4.tar.gz
wget http://cran.r-project.org/src/contrib/R2jags_0.02-15.tar.gz
sudo R --with-jags-modules=/usr/local/lib/JAGS/modules-2.2.0 CMD INSTALL rjags_2.2.0-4.tar.gz
sudo R --with-jags-modules=/usr/local/lib/JAGS/modules-2.2.0 CMD INSTALL R2jags_0.02-15.tar.gz
sudo R --with-jags-modules=/usr/local/lib/JAGS/modules-2.2.0 --arch=i386 CMD INSTALL rjags_2.2.0-4.tar.gz
sudo R --with-jags-modules=/usr/local/lib/JAGS/modules-2.2.0 --arch=x86_64 CMD INSTALL rjags_2.2.0-4.tar.gz
They certainly aren't all necessary, but they were sufficient!
I had the same problem while running Rstudio 0.97.237 and R 2.15.2. The issue had something to do with JAGS.
The fix: Update to JAGS 3-3 by downloading and installing it from here.
I encountered the error: unable to load shared object '/Library/Frameworks/R.framework/Resources/modules//R_X11.so': on my Mac and DuckDuckGo led me to this post. I was using R from the command line, so I can't speak to how it works with RStudio although I'm pretty sure it's the fix for that too. I updated JAGS from the SourceForge link provided in another answer. I can at least verify that it worked for me, though the developer was unsigned (I needed to ignore a MacOS warning during the installation procedure).

Resources