I have 4 files, Complex.java, Polynomial.java, Newton.java, and NewtonFractal.java whereby in each class we have:
Complex sets up a data type Complex() which can be seen as a point in R^2 with a real and imaginary part.
Polynomial sets up a polynomial of complex entries that is initialised by an array of complex entries.
- Newton which performs the Newton-Raphson algorithm that I have finished and I'm testing in main.
For some reason when I write:
Polynomial p = new Polynomial(coeff);
where coeff is of type Complex[]. I get the error
Exception in thread "main" java.lang.IllegalAccessError: failed to access class Polynomial from class Newton (Polynomial is in unnamed module of loader 'app'; Newton is in unnamed module of loader com.sun.tools.javac.launcher.Main$MemoryClassLoader @473b46c3) at Newton.main(Newton.java:169)
What's weird is I get no error for
Complex[] coeff = new Complex[] {new Complex(-1.0, 0.0), new Complex(), new Complex(), (1.0, 0.0)};
so the Complex class is being accessed fine just not the Polynomial class. I've deleted all previous class files, replaced them, and the locations of each loaders are:
- com.sun.tools.javac.launcher.Main$MemoryClassLoader@58c1c010 for Newton.java
- com.sun.tools.javac.launcher.Main$MemoryClassLoader@b62fe6d for Polynomial.java
- com.sun.tools.javac.launcher.Main$MemoryClassLoader@15eb5ee5 for Complex.java
which I got from running System.out.println("Insert Class Name".class.getClassLoader());
in main
and compiling for each file. I could not run System.out.println(Polynomial.class.getClassLoader());
from the Newton or Complex file, but I could run System.out.println(Complex.class.getClassLoader());
in Newton giving:
jdk.internal.loader.ClassLoaders$AppClassLoader@3d4eac69 for Newton.java. But I could not run the same code in the Complex file with Newton as the class. Also I can run getClassLoader() for Complex.java from Polynomial.java and I get jdk.internal.loader.ClassLoaders$AppClassLoader@3d4eac69. But I can't do the same for getClassLoader() for Polynomial.java from Complex.java giving:
Exception in thread "main" java.lang.IllegalAccessError: failed to access class Newton from class Polynomial (Newton is in unnamed module of loader 'app'; Polynomial is in unnamed module of loader com.sun.tools.javac.launcher.Main$MemoryClassLoader @b62fe6d) at Polynomial.main(Polynomial.java:135)
I'm new so I'm not sure what information is most useful to share so I tried to give everything but if anything else is needed don't hesitate to ask.