skip to Main Content

Caused by: java.lang.reflect.InaccessibleObjectException: Unable to make field private final java.lang.String java.io.File.path accessible: module java.base does not "opens java.io" to unnamed module @3ca6a01c

I took an android repo from github and build it successfullt.
But when I try to deploy it to my device it is giving above error.

I am using Android Studio Giraffe | 2022.3.1
My JAVA_HOME is C:Program FilesJavajdk-11

Earlier there was no JDK installed in laptop, saw online that, this problem might be because I am missing JDK 11 so installed it, expecting it to solve my problem but no results

2

Answers


  1. Java.lang.reflect.InaccessibleObjectException is a common error when dealing with module-based access control introduced in Java 9 and later. This error occurs when your code attempts to access private fields or methods within Java modules that are not accessible due to module restrictions.

    if your code relies on reflection to access private fields or methods, you can use the –add-opens option to open access to the relevant module. For example:

    java --add-opens java.base/java.io=ALL-UNNAMED YourMainClass
    
    Login or Signup to reply.
  2. you should add –add-opens java.base/java.io=ALL-UNNAMED YourMainClass
    at gradle.properties, just like this:

    org.gradle.jvmargs=-Xmx2048m 
    --add-exports=java.base/sun.nio.ch=ALL-UNNAMED 
    --add-opens=java.base/java.lang=ALL-UNNAMED 
    --add-exports=java.base/java.lang.reflect=ALL-UNNAMED 
    --add-opens=java.base/java.io=ALL-UNNAMED 
    --add-exports=jdk.unsupported/sun.misc=ALL-UNNAMED 
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search