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

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")

Related

jni.h file not found

I'm ultimately trying to install the RJDBC package on a mac running R 3.3.3 and Java 12 and Mojave OS.
When trying to install RDJBC I get the following error:
configure: error: One or more Java configuration variables are not set.
Make sure R is configured with full Java support (including JDK). Run
R CMD javareconf
as root to add Java support to R.
If you don't have root privileges, run
R CMD javareconf -e
to set all Java-related variables and then install rJava.
So then I go ahead and run R CMD javareconf in the terminal and I get the following error:
conftest.c:1:10: fatal error: 'jni.h' file not found
I've found various questions online around the same topic and have tried out suggested solutions and none have worked for me. Ity could be a combination of my OS/Java version. Would someone be willing to walk me through a fix here?
Update:
Stacktrace
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 in .jcheck(silent = FALSE) :
java.lang.NullPointerException.jcall(f, "Ljava/lang/Object;", "get", .jcast(ic, "java/lang/Object"))new("jobjRef", jobj = <pointer: 0x7fd4a04ac4b8>, jclass = "java/lang/NullPointerException")
Interestingly, it seems to work when I run R through terminal, but not in Rstudio.
This will need some tweaking. In general, R, Java and rJava are not quite easy things to setup when they are supposed to work together. Make sure to go through: http://www.owsiak.org/r-java-11-and-making-sure-you-can-load-rjava/
Note that due to changes in Java 12 it is no longer possible to dynamically affect location of shared libraries via reflection - this affects rJava. I am pretty sure you won't get rJava and any other JNI based codes working properly with Java 12 in R.
Once you have your R configured, it will work as expected
> R
R version 3.6.1 (2019-07-05) -- "Action of the Toes"
Copyright (C) 2019 The R Foundation for Statistical Computing
Platform: x86_64-apple-darwin15.6.0 (64-bit)
...
...
> install.packages("RJDBC")
--- Please select a CRAN mirror for use in this session ---
...
> library(RJDBC)
Loading required package: DBI
>
Update
For Java 12 try following. Inside ~/.profile add following line
export JAVA_HOME=$(/usr/libexec/java_home -v 12)
then, run
> sudo R CMD javareconf \
JAVA_HOME=${JAVA_HOME} \
JAVA=${JAVA_HOME}/bin/java \
JAVAC=${JAVA_HOME}/bin/javac \
JAVAH=${JAVA_HOME}/bin/javah \
JAR=${JAVA_HOME}/bin/jar
and, inside R
> system("java -version")
java version "12.0.1" 2019-04-16
Java(TM) SE Runtime Environment (build 12.0.1+12)
Java HotSpot(TM) 64-Bit Server VM (build 12.0.1+12, mixed mode, sharing)
> library(RJDBC)
Loading required package: DBI
Loading required package: rJava
>
Of course, you still need XCode.app as it contains headers for JNI.
Update
In order to make sure all the apps are getting Java 11 instead of Java 12 (not only CLI based) you can "disable" Java 12 following way.
cd /Library/Java/JavaVirtualMachines/jdk-12.0.1.jdk/Contents
sudo mv Info.plist Info.plist~
Since now, even though you haven't removed Java 12, RStudio will pick up correct version.

Java error in MacOS Mojavew when loading a package

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.

Error while using h2o.init() in R

I get the following error whenever I use h2o.init():
localh2o<-h2o.init()
H2O is not running yet, starting it now...
Error in system2(command, "-version", stdout = TRUE, stderr = TRUE) :
'""' not found
In addition: Warning message:
In .h2o.checkJava() :
Found JRE at C:/Program Files (x86)/Java/jre7/bin/java.exe but H2O requires the JDK to run
I am running it on RStudio Version 0.99.473 and R version 3.2.2, 64 bit os
The error message is pretty self-explanatory:
Found JRE at C:/Program Files (x86)/Java/jre7/bin/java.exe but H2O requires the JDK to run
You need to install the JDK and point the JAVA_HOME environment variable to the JDK directory (the parent of the bin directory), if it isn't automatically done by the installer.

RHive installation : Error in rhive.connect

I was installing rhive on my cluster. I followed below link for installation.
https://github.com/nexr/RHive
Everything went smooth except last line. When i tried to connect r with hive server , it is throwing below exception.
> library(RHive)
Loading required package: rJava
Loading required package: Rserve
> rhive.connect("127.0.0.1", 10000, hiveServer2)
Error: java.lang.UnsupportedClassVersionError: org/apache/hadoop/conf/Configuration : Unsupported major.minor version 51.0
>
Java Version
java -version
java version "1.7.0_67"
Java(TM) SE Runtime Environment (build 1.7.0_67-b01)
Java HotSpot(TM) 64-Bit Server VM (build 24.65-b04, mixed mode)
Does anyone has any clue here?
Issues got resolved when I changed my JAVA_HOME to jdk6. It looks like jdk7 is not supported.
echo $JAVA_HOME
/usr/lib/jvm/java-1.6.0-openjdk-1.6.0.36.x86_64/jre

Problems requiring rJava in Windows

I am using a 64-bit machine, with the latest version of R (3.1.2), the latest RStudio version (0.98.1091) and the latest JAVA (Version 8 Update 31).
I tried to require rJava (rJava_0.9-6) and the result is the following error:
require(xlsx)
Carregando pacotes exigidos: rJava
Error : .onLoad falhou em loadNamespace() para 'rJava', detalhes:
chamada: fun(libname, pkgname)
erro: No CurrentVersion entry in Software/JavaSoft registry! Try re-installing Java and make sure R and Java have matching architectures.
Failed with error: ‘package ‘rJava’ could not be loaded’
I already tried to re-install Java with no sucess.
Does anybody know how can I solve this problem?
I think the problem on this occasion is that your Java is 32-bit, whereas your R is 64-bit. This is why you get a R and Java have different architectures error.
In order to check what your Java version is on Windows type:
java -d64 -version
on the command line as it is mentioned here.
I think that once you install the correct Java version i.e. the 64-bit on this occasion then loading your xlsx library will work!
The architecture of Java you get for install from the regular Java download web page depends on the architecture of browser you’re using (32-bit or 64-bit) when you download it. This happens without any fanfare. Try the Java manual download page, select the 64-bit version of Java for your OS, install it, and then (after restarting R) try your R packages again.

Resources