Why can't R load the shared object?

I am trying to use the XLConnect library in R. If I run

 library(XLConnect) 

The following error message appears:

 JAVA_HOME cannot be determined from the Registry 

To solve this problem, I first set the JAVA_HOME variable:

 Sys.setenv(JAVA_HOME='C:/Program Files (x86)/Java/jre1.8.0_65') library(XLConnect) 

It seems like this helps me move on, but then I get another problem:

 unable to load shared object 'C:/Program Files/R/R-3.2.2/library/rJava/libs/x64/rJava.dll' 

I wonder why R cannot load rJava.dll . At least this file is in the folder where R is looking for it:

 C:\Program Files\R\R-3.2.2\library\rJava\libs\x64 

ADDED

Note that the rJava.dll file exists, and it is where R is looking for it. I assume the problem is incompatibility between 32-bit and 64-bit versions. I assume that since R complains:

 % 1 is not a valid Win32 application 

Well, why does R expect this to be a Win32 application`? First, my OS is 64bit, second my Java is also for the 64bit and finally, the `rJava.dll` object is located in the folder with Win32 application`? First, my OS is 64bit, second my Java is also for the 64bit and finally, the `rJava.dll` object is located in the folder with x64` in the name (so I assume this is also a 64-bit version).

+7
r xlconnect
source share
2 answers

I ran into the same problem. Please find jvm.dll (your version of JRE may differ)

 C:\Program Files (x86)\Java\jre1.8.0_65\bin\client 

or

 C:\Program Files (x86)\Java\jre1.8.0_65\bin\server 

add this path to your windows system path and you're good to go. but keep in mind that the version of jre and R should be consistent if your java is in Program Files , its 64-bit, so run from 64 bit R if it is 32 bit in Program Files (x86) , so use 32 bit R

as in my case, it showed an error in 64-bit enter image description here

but worked fine in 32 bit enter image description here

+3
source share

You used / instead of \ .

 Sys.setenv(JAVA_HOME='C:\\Program Files (x86)\\Java\\jre1.8.0_65') library(XLConnect) 

I am using UNIX. Therefore, I cannot verify this myself, but your path may be wrong.

According to this message, you can search at this address:

 find.java <- function() { for (root in c("HLM", "HCU")) for (key in c("Software\\JavaSoft\\Java Runtime Environment", "Software\\JavaSoft\\Java Development Kit")) { hive <- try(utils::readRegistry(key, root, 2), silent = TRUE) if (!inherits(hive, "try-error")) return(hive) } hive } 

credit goes to @nograpes for this feature and an article for helping me give you an answer.

+1
source share

All Articles