user7201984
user7201984

Reputation: 31

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

Upvotes: 3

Views: 4416

Answers (2)

I re-installed rJava and it worked!

Using: install.packages("rjava")

Upvotes: 0

user85786
user85786

Reputation: 1

  1. Navigate to /Library/Java/JavaVirtualMachines and remove JDK 12
  2. Reinstall JDK 11.
  3. sudo R CMD javareconf in the terminal.

Upvotes: 0

Related Questions