installing packages problems

i have updated my R studio version. Since i have done this i got problems in installing any package. I have macOS mojava 10.14.5 . R studio version 1.2.1335 , R version 3.6.1.
i have typed :
update.packages()
install.packages("xlsx" )

i got this message
"trying URL 'https://cran.rstudio.com/bin/macosx/el-capitan/contrib/3.6/xlsx_0.6.1.tgz'
Content type 'application/x-gzip' length 461752 bytes (450 KB)

downloaded 450 KB

The downloaded binary packages are in
/var/folders/50/l77935nj58x3f3rx856d7vxm0000gn/T//RtmpSdSh33/downloaded_packages"

and by writing :
library(xlsx)

so i got
"Error: package or namespace load failed for ‘xlsx’:
.onLoad failed in loadNamespace() for 'rJava', details:
call: dyn.load(file, DLLpath = DLLpath, ...)
error: unable to load shared object '/Library/Frameworks/R.framework/Versions/3.6/Resources/library/rJava/libs/rJava.so':
dlopen(/Library/Frameworks/R.framework/Versions/3.6/Resources/library/rJava/libs/rJava.so, 6): Library not loaded: /Library/Java/JavaVirtualMachines/jdk-11.0.1.jdk/Contents/Home/lib/server/libjvm.dylib
Referenced from: /Library/Frameworks/R.framework/Versions/3.6/Resources/library/rJava/libs/rJava.so
Reason: image not found "

I have tried to solve this problem since a while and didn't manage. Any help is appreciated

This problem is specific to packages that depend on Java, do you have java installed in your system? If so, try running this command in your system terminal and then restart Rstudio

sudo R CMD javareconf

Also, after updating R is good to update packages using checkBuilt

update.packages(checkBuilt = TRUE)

Thank you so much for answering me , yes i have updated the packages and i do have java before i wrote this post. so i don't know where does the problem come from.

i have typed the command you wrote here and i got this
"
Java interpreter : /usr/bin/java
Java version : 1.6.0_65
Java home path : /Library/Java/JavaVirtualMachines/1.6.0.jdk/Contents/Home
Java compiler : /usr/bin/javac
Java headers gen.: /usr/bin/javah
Java archive tool: /usr/bin/jar

trying to compile and link a JNI program
detected JNI cpp flags :
detected JNI linker flags : -L/Library/Java/JavaVirtualMachines/1.6.0.jdk/Contents/Libraries -ljvm
clang -I"/Library/Frameworks/R.framework/Resources/include" -DNDEBUG -isysroot /Library/Developer/CommandLineTools/SDKs/MacOSX.sdk -I/usr/local/include -fPIC -Wall -g -O2 -c conftest.c -o conftest.o
conftest.c:1:10: fatal error: 'jni.h' file not found
#include <jni.h>
^~~~~~~
1 error generated.
make: *** [conftest.o] Error 1
Unable to compile a JNI program

JAVA_HOME : /Library/Java/JavaVirtualMachines/1.6.0.jdk/Contents/Home
Java library path:
JNI cpp flags :
JNI linker flags :
Updating Java configuration in /Library/Frameworks/R.framework/Resources
Done.
"
i think the problem is here

It seems like you have have an incompatible or corrupted version of Java, try installing this one.

https://www.oracle.com/technetwork/java/javase/downloads/jdk8-downloads-2133151.html

Thats true . I have installed java version "1.6.0_65" from before and i have tried to uninstall it and install a new compatible one but i can't uninstall the old one .i have typed this in my consul
sudo rm -fr ~/library/Java/JavaVirtualMachines/jdk1.6.0_65.jdk
sudo rm -fr /Library/Internet\ Plug-Ins/JavaAppletPlugin.plugin
sudo rm -fr /Library/PreferencePanes/JavaControlPanel.prefPane
sudo rm -fr ~/Library/Application\ Support/Oracle/Java

i have tried also the oracle uninstall tool and instructions here:
https://www.java.com/en/download/help/mac_uninstall_java.xml
but I'm still stuck with this java 1.6.0_65