#Help resolving Java Linkage Error

29 messages · Page 1 of 1 (latest)

thorn carbon
#

Hello dear people,

I am currently doing university homework and am experiencing an error which I cannot seem to fix 😦.
This is the error message:

Exception in thread "main" java.lang.LinkageError: loader constraint violation: loader 'app' wants to load class Tree. A different class with the same name was previously loaded by com.sun.tools.javac.launcher.Main$MemoryClassLoader @6af93788. (Tree is in unnamed module of loader com.sun.tools.javac.launcher.Main$MemoryClassLoader @6af93788, parent loader 'app')
        at java.base/java.lang.ClassLoader.defineClass1(Native Method)
        at java.base/java.lang.ClassLoader.defineClass(ClassLoader.java:1013)
        at java.base/java.security.SecureClassLoader.defineClass(SecureClassLoader.java:150)
        at java.base/jdk.internal.loader.BuiltinClassLoader.defineClass(BuiltinClassLoader.java:862)
        at java.base/jdk.internal.loader.BuiltinClassLoader.findClassOnClassPathOrNull(BuiltinClassLoader.java:760)
        at java.base/jdk.internal.loader.BuiltinClassLoader.loadClassOrNull(BuiltinClassLoader.java:681)
        at java.base/jdk.internal.loader.BuiltinClassLoader.loadClass(BuiltinClassLoader.java:639)
        at java.base/jdk.internal.loader.ClassLoaders$AppClassLoader.loadClass(ClassLoaders.java:188)
        at java.base/java.lang.ClassLoader.loadClass(ClassLoader.java:521)
        at TreeListElement.toString(TreeListElement.java:34)
        at TreeList.toString(TreeList.java:20)
        at Tree.toString(Tree.java:32)
        at Tree.main(Tree.java:71)
supple wraithBOT
#

This post has been reserved for your question.

Hey @thorn carbon! Please use /close or the Close Post button above when your problem is solved. Please remember to follow the help guidelines. This post will be automatically closed after 300 minutes of inactivity.

TIP: Narrow down your issue to simple and precise questions to maximize the chance that others will reply in here.

thorn carbon
#

If relevant, I can share the sourcefiles in question

#

As for my setup, I just have 3 files in a common folder and using java[c] directly

#

my files compile just fine, the error occurs once I try and run the main method in Tree.java

#

this is the folder structure for reference

#

just these files in the same folder

boreal dawn
#

so you are in the folder with the three source files and first run javac * and then java Tree and that produces the LinkageError ?

#

and there are no other files in that folder other than the mentioned source files ?

thorn carbon
#

yep

#

deleted the generated class files from previous compilatons just to be sure, still didnt work

thorn carbon
boreal dawn
#

what are the outputs of:
java --version
and
where java

thorn carbon
#

C:\Program Files\Java\jdk-19.0.1\bin\java.exe

boreal dawn
#

and you are running the compiled class files with java Tree not java Tree.java correct ?

thorn carbon
#

wait im actually not sure, let me try both

boreal dawn
#

the second one will produce the LinkageError

thorn carbon
#

oh wow, the first one works!!

#

thank you a lot mr fish sticks

supple wraithBOT
# thorn carbon thank you a lot mr fish sticks

If you are finished with your post, please close it.
If you are not, please ignore this message.
Note that you will not be able to send further messages here after this post have been closed but you will be able to create new posts.

thorn carbon
#

but whats the semantic difference between those invocations

boreal dawn
#

In newer version of java. The java command can be used to run single file applications if the file in question is passed to the command with its extension java [filename].java. I assume that an internal javac classloader is completely separate from the "normal" classloader hierachy mening that when it tries to load the already compiled classes (that wouldn't be possible if the classes weren't compiled beforehand) it will throw that LinkageErrror. However, I can't give you a detailed explanation because I know too little about the inner workings of the java command.

thorn carbon
#

ah

#

thank you for everything!

supple wraithBOT
# thorn carbon thank you for everything!

If you are finished with your post, please close it.
If you are not, please ignore this message.
Note that you will not be able to send further messages here after this post have been closed but you will be able to create new posts.

thorn carbon
#

.close