0

I'm trying to make a class loader that will load .class files inside a .zip file. I followed this tutorial (https://weblogs.java.net/blog/2008/07/25/how-load-classes-jar-or-zip), but when i run the program, i get this error:

java.lang.LinkageError: loader (instance of org/freeforums/geforce/genforcer/main/ZipClassLoader): attempted duplicate class definition for name: "test/TestClass"

The error comes from line 30, which is:

return defineClass(filename, out.toByteArray, 0, out.size());

I call the method by using:

zipClassLoaderObj.findClass("test.TestClass");

Does anyone know what i'm doing wrong?

9
  • Is that class already on the classpath? Commented Feb 27, 2014 at 19:00
  • Sorry, i'm brand new to using ClassLoader's and other semi-advanced features. Could you explain what that means? Commented Feb 27, 2014 at 19:05
  • What I'm asking has nothing to do with classloaders or much else. I'm asking if when you run the program the class is already on the classpath, loaded, etc. Commented Feb 27, 2014 at 19:08
  • Oh, yeah, it's loaded. I added the line from which the error originates from to the main post. Commented Feb 27, 2014 at 19:12
  • Subclasses of LinkageError indicate that a class has some dependency on another class; however, the latter class has incompatibly changed after the compilation of the former class. Although it's something of a "garbage" error. I suspect in this case you get it because you've already loaded a version of test/TestClass. Commented Feb 27, 2014 at 19:16

1 Answer 1

1

Found the problem. I was calling the method two times because it was in a 'for' loop with a bunch of other code. Just took it out of the loop, and now it works perfectly. Don't know why i couldn't figure that out myself. Thanks for the help!

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.