Java.lang.IllegalAccessError: не удалось получить доступ к классуJAVA

Программисты JAVA общаются здесь
Гость
Java.lang.IllegalAccessError: не удалось получить доступ к классу

Сообщение Гость »


Consider the following Java class structure:

public class myClass { class myInnerClass {} } After compiling with the command javac myClass.java, two class files are generated: myClass.class and myClass$myInnerClass.class.

i got 2 files: myClass.class and myClass$myInnerClass.class

In a separate Main.java file, I am using URLClassLoader to dynamically load myClass.class and execute a method from it that involves the usage of the myInnerClass. However, I encountered the following error:

java.lang.IllegalAccessError: failed to access class myClass$myInnerClass from class myClass (myClass$myInnerClass is in unnamed module of loader 'app'; myClass is in unnamed module of loader java.net.URLClassLoader @41cf53f9) How can I resolve this issue?

I attempted to modify the classpath or module path when using URLClassLoader to ensure proper module accessibility.

I expected the dynamically loaded myClass to successfully access and utilize myInnerClass without encountering the IllegalAccessError. However, the issue persists despite my attempts.


Источник: https://stackoverflow.com/questions/781 ... cess-class

Вернуться в «JAVA»