Java,IllegalAccessorError:超类访问检查失败 [英] Java, IllegalAccessorError: superclass access check failed
问题描述
我一直在用Java开发自己的一个小项目,最近,我对其进行了编译并收到此错误:
I've been working on a little project of my own in Java, and recently, I compiled it and received this error:
线程"main"中的异常java.lang.IllegalAccessError:超类访问检查失败:类kröw.zeale.v1.program.core.DataManager$ ConstructList(在未命名模块@ 0x4563e9ab中)无法访问类com.sun.javafx. collections.ObservableListWrapper(在javafx.base模块中),因为模块javafx.base不会将com.sun.javafx.collections导出到未命名的模块@ 0x4563e9ab
Exception in thread "main" java.lang.IllegalAccessError: superclass access check failed: class kröw.zeale.v1.program.core.DataManager$ConstructList (in unnamed module @0x4563e9ab) cannot access class com.sun.javafx.collections.ObservableListWrapper (in module javafx.base) because module javafx.base does not export com.sun.javafx.collections to unnamed module @0x4563e9ab
背景:
因此,我目前有三个不同的类,它们都在同一个程序包中.我的层次结构如下:
Background:
So, I currently have three different classes, all in the same package. My hierarchy is as follows:
• Kröw
• DataManager
♦ ConstructList
在我程序的早期版本中,我的层次结构是这样的:
In previous versions of my program, my hierarchy was like this:
• Kröw
♦ DataManager
- ConstructList
在两种情况下,ConstructList
都扩展了com.sun.javafx.collections.ObservableListWrapper<Construct>
. (我认为这里的Construct
类不是必需的,我不想显示它,但是如果需要的话,我可以显示.)
In both cases, ConstructList
extended com.sun.javafx.collections.ObservableListWrapper<Construct>
. (I don't think that the class Construct
is necessary here and I'd rather not show it, but I can if needed.)
无论如何,现在,我的IDE可以按预期运行该应用程序,但是,当我导出该应用程序时,上面的异常给了我.
Anyways, right now, my IDE can run the application as expected, however, when I export it, the above exception is given to me.
完整堆栈跟踪:
Exception in thread "main" java.lang.IllegalAccessError: superclass access check failed: class kröw.zeale.v1.program.core.DataManager$ConstructList (in unnamed module @0x4563e9ab) cannot access class com.sun.javafx.collections.ObservableListWrapper (in module javafx.base) because module javafx.base does not export com.sun.javafx.collections to unnamed module @0x4563e9ab
at java.base/java.lang.ClassLoader.defineClass1(Native Method)
at java.base/java.lang.ClassLoader.defineClass(Unknown Source)
at java.base/java.security.SecureClassLoader.defineClass(Unknown Source)
at java.base/jdk.internal.loader.BuiltinClassLoader.defineClass(Unknown Source)
at java.base/jdk.internal.loader.BuiltinClassLoader.findClassOnClassPathOrNull(Unknown Source)
at java.base/jdk.internal.loader.BuiltinClassLoader.loadClassOrNull(Unknown Source)
at java.base/jdk.internal.loader.BuiltinClassLoader.loadClass(Unknown Source)
at java.base/jdk.internal.loader.ClassLoaders$AppClassLoader.loadClass(Unknown Source)
at java.base/java.lang.ClassLoader.loadClass(Unknown Source)
at kröw.zeale.v1.program.core.DataManager.<init>(DataManager.java:22)
at kröw.zeale.v1.program.core.DataManager.getDataManager(DataManager.java:63)
at kröw.zeale.v1.program.core.Kröw.<clinit>(Kröw.java:23)
错误中提到的类Kröw
的一部分:
Part of class Kröw
that is mentioned in the error:
private static final DataManager DATA_MANAGER = DataManager.getDataManager(); // line 23
错误中提到的类DataManager
的部分:
Parts of class DataManager
that are mentioned in the error:
static DataManager getDataManager() { // line 66
return new DataManager();
}
和
public final ConstructList constructs = new ConstructList(); // line 22
类ConstructList
:
Class ConstructList
:
public class ConstructList extends ObservableListWrapper<Construct> { // line 209
private ConstructList() {
super(new ArrayList<>()); // line 212
}
public LinkedList<Construct> getDeadConstructs() {
...
}
public LinkedList<Construct> getLivingConstructs() {
...
}
}
现在,我已经查看了可以找到的资源,例如 IllegalAccessError SO问题
Now, I have looked at the resources that I could find, such as IllegalAccessError SO Question
(请注意这是怎么说的:尝试访问方法"而不是超类访问检查失败" )
该解决方案的公认答案是检查编译的jar文件和我的源代码之间是否有任何不同,因此我尝试了一下,发现有一些细微的差异.这是我反编译的jar文件中更改后的代码行. (使用 JD-GUI 反编译)
The accepted answer to that solution was to check if anything is different between the compiled jar file and my source code, so I tried that and found some minor differences. Here are the changed lines of code from my decompiled jar file. (Decompiled using JD-GUI)
Class DataManager
:
Class DataManager
:
public final ConstructList constructs = new ConstructList(null);
曾经是:
public final ConstructList constructs = new ConstructList();
类ConstructList
:
Class ConstructList
:
private ConstructList() {
super();
}
曾经是:
private ConstructList() {
super(new ArrayList<>());
}
现在,在反编译的代码中,ConstructList()
构造函数没有任何参数,而且我看到它是通过传入的null
来调用的,这对我来说似乎是一个错误,但我不确定是否这是我例外的原因,我无法通过互联网找到任何东西,这就是我来这里的原因.
Now, in the decompiled code, the ConstructList()
constructor does not have any parameters, and I see it being invoked with null
being passed in, which looks like an error to me, but I'm not sure if it is the cause of my exception and I haven't been able to find anything via the internet, which is why I came here.
另一方面,我给出的反编译代码是由我的IDE使用其导出功能创建的.我想看看构造函数中的null
参数是否是问题,但我不知道如何以不同的方式编译我的代码以反映这一点.如果有人知道如何更改正在获取的导出代码,请通知我.
On another note, the decompiled code I've given was created by my IDE, using its export function. I would like to see if the null
argument with my constructor is the problem, but I do not know how to compile my code in a different way to reflect that. If someone knows how I can change the exported code I am getting, please inform me.
无论如何,我想知道的是此异常是由我的代码的哪个部分引起的,以及如何解决该问题.
Anyways, what I want to know is what part of my code this exception is caused by, and how I can fix it.
推荐答案
事实证明,您正在使用Java 9进行编译,该Java利用了JDK的新module
系统.通过实现模块,可能存在一种解决您的问题的有效方法,但是另一种解决方案是简单地使用Java 8进行编译!
It turns out you were compiling with Java 9 which utilizes the JDK's new module
system. There is probably a valid way to fix your problem by implementing modules, however another solution is to simply compile with Java 8!
这篇关于Java,IllegalAccessorError:超类访问检查失败的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!