我昨天买了一台新电脑(Dell XPS 13)。我刚刚安装了 JDK 并将我所有的旧 Java 项目复制到我的新设备上,但是当我尝试运行这些程序中的任何一个时,我都会遇到非法访问错误。
编辑:注意:在升级之前我使用的是 jdk1.8.0_151。我现在正在使用 jdk-12.0.2。
我已经尝试重新编译某些项目中的所有类,但这没有帮助。请注意,非法访问错误仅在运行时发生。我看过其他关于非法访问错误的 stackoverflow 帖子,但他们的解决方案都不适合我。
Exception in thread "main" java.lang.IllegalAccessError: failed to access class Tree from class BinTree (Tree is in unnamed module of loader 'app'; BinTree is in unnamed module of loader com.sun.tools.javac.launcher.Main$MemoryClassLoader @48a242ce)
at BinTree.main(BinTree.Java:12)
编辑:该项目的项目层次结构是:
BinTree:
Tree:
Node
编辑:这是项目的主要类:
import java.util.Scanner;
import java.util.ArrayList;
class BinTree {
public static void main(String[] args) {
//Create randomized values for a new tree
ArrayList<Double> toSort = new ArrayList<Double>();
for (int i = 1; i <= 1300; i++) {
double rand = 1 + ((int)(Math.random()*100000));
toSort.add(rand);
}
//Create tree
Tree binTree = new Tree(toSort);
binTree.getGreatestNode();
binTree.sort();
}
}