1

I tried to load the R package xlsx:

library('xlsx')

But I got the following error:

Error : .onLoad failed in loadNamespace() for 'xlsx', details:
  call: .jinit()
  error: Cannot create Java virtual machine (-1)
In addition: Warning message:
package ‘xlsx’ was built under R version 3.2.3 
Error: package or namespace load failed for ‘xlsx’

My R-session aborts when I try .jinit()

Any help is much appreciated.

Edit:

I updated R Studio to the newest version and executed

update.packages(checkBuilt = TRUE)

but still got the following error:

Error : .onLoad failed in loadNamespace() for 'xlsx', details:
  call: .jinit()
  error: Cannot create Java virtual machine (-1)
Error: package or namespace load failed for ‘xlsx’

Edit 2:

This question is still unsolved. As Pascal in the comments below suggested I looked for the windows equivalent command of:

R CMD javareconf

After many hours of searching I still didn't found it.

8128
  • 27
  • 2
  • 6
  • Upgrade R, `R CMD javareconf` and `update.packages(checkBuilt = TRUE)` –  Feb 02 '16 at 14:57
  • It would seem you have the wrong version of R. Suggest updating. – MichaelChirico Feb 02 '16 at 14:57
  • @Pascal: could you please elaborate on what you mean with 'R CMD javareconf ' – 8128 Feb 02 '16 at 15:27
  • I would say it is written in the documentation. –  Feb 02 '16 at 23:04
  • @Pascal: I have no idea to which documentation you refer. Please be more specific – 8128 Feb 03 '16 at 10:57
  • https://cran.r-project.org/doc/manuals/r-devel/R-admin.html#Java-support –  Feb 03 '16 at 13:59
  • @Pascal: Thanks for your reply. You do refer to the windows command prompt right? If I run 'R CMD javareconf', I get the error "'R' is not recognized as an internal or external command, operable program or batch file". – 8128 Feb 03 '16 at 15:37
  • If you are on Windows, the command is different. Please search. Last comment. –  Feb 03 '16 at 22:45
  • @Pascal: I did a long but unfortunately unsuccesful search. I found comparisons between linux and windows commands like this:http://www.yolinux.com/TUTORIALS/unix_for_dos_users.html But I never found the windows equivalent of 'R CMD javareconf' – 8128 Feb 04 '16 at 08:15

2 Answers2

0

I faced similar problem on Macbook. If you've upgraded Java recently, it is likely that you need to reconfigure.

For me, it got solved with,

step#1 sudo R CMD javareconf (On Windows, sudo not required. If you face "command not found" issue on Windows, try this)

step#2 install.packages("rJava",type='source') (inside R prompt)

Hope this helps!

SanjayIV
  • 748
  • 5
  • 6
-1

In case you don't have PATH variable set up properly, try to override it by using

options(java.home="PATH TO jre")

This might fix some issues.

Zakkery
  • 420
  • 4
  • 11