I got a new computer yesterday (Dell XPS 13). I just installed the JDK and copied all of my old Java projects over to my new device, but when I try to run any of these programs I get an illegal access error.
Edit: Note: Before the upgrade I was using jdk1.8.0_151. I am now using jdk-12.0.2.
I've tried recompiling all of the classes within some of the projects, but this doesn't help. Note that the illegal access error only occurs at runtime. I've seen other stackoverflow posts about illegal access errors, but none of their solutions worked for me.
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)
Edit: The project hierarchy for this project is:
BinTree:
Tree:
Node
Edit: This is the main class of the project:
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();
}
}
Try to compile all the .java
source file of your project at once. If you have all three files BinTree
, Tree
and Node
in the same directory, then you can easily go to that directory using cmd/terminal and write:
javac *.java
It should compile all the java file on that directory at once.