3

我昨天买了一台新电脑(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();
        }
    }
4

1 回答 1

1

尝试一次编译.java项目的所有源文件。如果您拥有所有三个文件BinTreeTree并且Node在同一个目录中,那么您可以使用 cmd/terminal 轻松转到该目录并编写:

javac *.java

它应该一次编译该目录中的所有 java 文件。

于 2019-08-09T18:33:46.537 回答