s-u / rJava

R to Java interface
https://RForge.net/rJava
235 stars 77 forks source link

Error: package or namespace load failed for ‘rJava’ #318

Closed KJMTosteo closed 11 months ago

KJMTosteo commented 11 months ago

Hi, I am getting an error when loading rJava. I have reviewed StackOverflow and unable to solve it. Any help?

Error code is below.

library("rJava") Error: package or namespace load failed for ‘rJava’: .onLoad failed in loadNamespace() for 'rJava', details: call: inDL(x, as.logical(local), as.logical(now), ...) error: unable to load shared object 'C:/Users/user_name/AppData/Local/R/win-library/4.2/rJava/libs/x64/rJava.dll': LoadLibrary failure: %1 is not a valid Win32 application. In addition: Warning message: package ‘rJava’ was built under R version 4.2.3

I have done the following:

remove.packages("rJava") Removing package from ‘C:/Users/user_name/AppData/Local/R/win-library/4.2’ (as ‘lib’ is unspecified)

install.packages("rJava", type = "win.binary") package ‘rJava’ successfully unpacked and MD5 sums checked

I have also tired to: Installed the new JDK Development Kit 21.0.1 downloads from https://www.oracle.com/java/technologies/downloads/ Check Java Path and JAVA_HOME environment variable and it is pointing to the Java installation directory. (C:\Program Files\Java\jdk-21)

Cmd file when running: java -version java version "21.0.1" 2023-10-17 LTS Java(TM) SE Runtime Environment (build 21.0.1+12-LTS-29) Java HotSpot(TM) 64-Bit Server VM (build 21.0.1+12-LTS-29, mixed mode, sharing)

s-u commented 11 months ago

Please do NOT set JAVA_HOME it is detected automatically so only expert users should set it by hand in special situations.

Make sure you have installed 64-bit version of the JDK.

Can you find the location of jni.dll in your installed JDK?

KJMTosteo commented 11 months ago

Thanks! I removed JAVA_HOME and removed and reinstalled the packaged and it worked. Thanks so much for your help and the quick response.