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

  • Home
  • SEARCH
  • 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 8386899
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T18:04:21+00:00 2026-06-09T18:04:21+00:00

I have been playing around with a CustomerClassLoader as i am trying to load

  • 0

I have been playing around with a CustomerClassLoader as i am trying to load a .class file into JUnitCore.runClasses(...); but i am getting the following error

Exception in thread "AWT-EventQueue-0" java.lang.NoClassDefFoundError: SimpleTest (wrong name: JUnit/SimpleTest)
at java.lang.ClassLoader.defineClass1(Native Method)
at java.lang.ClassLoader.defineClass(ClassLoader.java:791)
at java.lang.ClassLoader.defineClass(ClassLoader.java:634)
at Java.CustomClassLoader.access$000(CustomClassLoader.java:16)
at Java.CustomClassLoader$1.run(CustomClassLoader.java:45)
at java.security.AccessController.doPrivileged(Native Method)
at Java.CustomClassLoader.findClass(CustomClassLoader.java:33)
at java.lang.ClassLoader.loadClass(ClassLoader.java:423)
.....

I don’t know what it wrong as I am passing in the correct class name and path for the class. here is the code that i am using

CustomClassLoader

import java.io.FileInputStream;
import java.security.AccessControlContext;
import java.security.AccessController;
import java.security.PrivilegedExceptionAction;

public class CustomClassLoader extends ClassLoader {

String repoLocation = "C:/TempBINfolder/bin/JUnit/";

public CustomClassLoader() { }

public CustomClassLoader(ClassLoader parent) {
super(parent);
}

@Override
protected Class<?> findClass(final String name)
throws ClassNotFoundException {

AccessControlContext acc = AccessController.getContext();

try {
return (Class)AccessController.doPrivileged(
 new PrivilegedExceptionAction() {
  public Object run() throws ClassNotFoundException {

   FileInputStream fi = null;
   try {

    String path = name.replace('.', '/');
    fi = new FileInputStream(repoLocation + path
      + ".class");
    byte[] classBytes = new byte[fi.available()];
    fi.read(classBytes);
    return defineClass(name, classBytes, 0,
      classBytes.length);
   }catch(Exception e )
   {
    throw new ClassNotFoundException(name);
   }
  }
 }, acc);
} catch (java.security.PrivilegedActionException pae) {
return super.findClass(name);
}
}
}

And this is how i am calling it

ClassLoader cls= new CustomClassLoader(ClassLoader.getSystemClassLoader());
Class stringClass = null;
    try {
        stringClass = cls.loadClass("SimpleTest");
    } catch (ClassNotFoundException ex) {
        Logger.getLogger(CompilerForm.class.getName()).log(Level.SEVERE, null, ex);
    }
    try {
        stringClass.newInstance();
    } catch (InstantiationException ex) {
        Logger.getLogger(CompilerForm.class.getName()).log(Level.SEVERE, null, ex);
    } catch (IllegalAccessException ex) {
        Logger.getLogger(CompilerForm.class.getName()).log(Level.SEVERE, null, ex);
    }

    JUnitCore.runClasses(stringClass);

Does anyone know why i am getting this error?

  • 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-06-09T18:04:23+00:00Added an answer on June 9, 2026 at 6:04 pm

    Change

    stringClass = cls.loadClass("SimpleTest");

    to
    stringClass = cls.loadClass("JUnit.SimpleTest");

    (i.e Add the fully qualified package name of the class file)

    and

    String repoLocation = "C:/TempBINfolder/bin/JUnit/";

    to
    String repoLocation = "C:/TempBINfolder/bin/";

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have been playing around with Google Apps Script today and I am trying
I have been playing around with NSURLConnection. Now I'm trying to grab some data
I have been playing around with zxing over the weekend, and have ran into
I have been playing around with Dynamic Data but I find the filtering and
We have been playing around with the canvas element, but are encountering sluggishness on
I have been playing around lately with head.js but I have found a stranger
Have been playing around with linq but there is one thing I cant seem
I have been playing around with the postgresql.conf file for a couple days now.
I have been playing around with the code found here . I'm getting things
I have been playing around with the merge command in R and am trying

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.