Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6378731
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T02:02:45+00:00 2026-05-25T02:02:45+00:00

I have three files: ScriptProcessor.java: public interface ScriptProcessor { public String someMethod(); } ScriptProcessorDummy.java:

  • 0

I have three files:

ScriptProcessor.java:

public interface ScriptProcessor {
   public String someMethod();
}

ScriptProcessorDummy.java:

public class ScriptProcessorDummy implements ScriptProcessor {
   public String someMethod{
       return "some string";
   }
}

In the main method, the code does the following:

URLClassLoader loader = null;
loader = new URLClassLoader(new URL[] {new URL("JARFILE")});
if (loader != null) {
   ScriptProcessor processor = (ScriptProcessor) loader.loadClass("ScriptProcessorDummy").newInstance();
}

“JARFILE” contains class files of ScriptProcessor and ScriptProcessorDummy.

The code works fine when using JDK 1.4 but when using JDK 1.5, the typecast (to ScriptProcessor) fails with java.lang.ClassCastException.

Could somebody please tell me how to fix this.

Thanks,
Raj

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-25T02:02:46+00:00Added an answer on May 25, 2026 at 2:02 am

    You need to make your current class loader the parent of the new class loader you are loading, and make sure that there isn’t a copy of the interface in your jar.

    The problem you have suggests that you have two copies of the interface: one in the main class loader, one in your new one. The object returned uses the one in the separate jar, but your class is using the main one. They aren’t the same. You have to make sure that Java uses the same ‘.class’ for the interface when processing the loaded class as it did when it compiled your code.

    The first thing to do is ‘jar tf’ on the jar and see if my hypothesis of two copies is correct. If so, remove it. Try running. If you now get a NoClassDef, fix the construction of the loader.

    new URLClassLoader(urlArray, Thread.currentThread().getContextClassLoader());
    

    assuming that your environment maintains the context class loader. Alternatively,

    new URLClassLoader(urlArray, ScriptProcessor.class.getClassLoader());
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have three files: one called sql.php witch has a class db that I
In Unix, I have got three main files. One of them is a library
I have some xml data contained in three files (Database.xml, Participants.xml, and ConditionTokens.xml). I
I have three files: Main, slist.h and slist.cpp can be seen at http://forums.devarticles.com/c-c-help-52/confused-why-i-am-getting-c2143-and-c1010-error-259574.html I'm
I have three files. The XML, the draw function and the main Activity. I
I have three files in a folder 'test' one.php two.php print.html And i have
Say I have three files (template_*.txt): template_x.txt template_y.txt template_z.txt I want to copy them
Suppose that I have those three files: a.h //a.h header #include <stdio.h> int int_variable;
For example, if I have three ASCII files: file1.txt file2.txt file3.txt ...and I wanted
I have the simplest code that I want to separate in three files: Header

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.