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 8106115
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T00:21:59+00:00 2026-06-06T00:21:59+00:00

I want to run the constructor of the Main.class in the package Test2, located

  • 0

I want to run the constructor of the Main.class in the package Test2, located in the folder C:\classes\

This is the code I’m using. It throws a class not found exception when it tries to turn it into a class. And then once it’s part of the class object, will the constructor automatically be run, or do I have to instance it somehow? Test2 is inputted into this code as text.

    if (Main.os.equals("Windows"))
    {
        String path = "C:\\classes\\";
    }
    else
    {
        String path = "~/classes/";
    }

    File file = new File(path);

    try
    {
        URL url = file.toURI().toURL();
        URL[] urls = new URL[]{url};
        Main.print("Stage 1");
        ClassLoader cl = new URLClassLoader(urls);
        Main.print("Stage 2");
        Class cls = cl.loadClass(text + ".Main");
        Main.print(text + " was loaded into memory.");
        close();
    }
    catch (MalformedURLException e)
    {
        e.printStackTrace();
    }
    catch (ClassNotFoundException e)
    {
        e.printStackTrace();
    }
  • 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-06T00:22:01+00:00Added an answer on June 6, 2026 at 12:22 am

    I suspect your problem is one of the following:

    1. file doesn’t exist or hasn’t been properly specified. Check via file.exists()
    2. Your class file is not located in the correct directory. If the package declaration for the Main class is package Test2; then your class file must be in the following location: C:\classes\Test2\Main.class.
    3. If Main is nested class, then you will need to refer to the enclosing class when loading it, eg cl.loadClass("Test2.EnclosingClass$Main");

    My guess it that your problem is number 2! 🙂

    Good luck.

    Oh, and yes, you’ll need to create an instance of your object if you want the constructor to be called: clazz.newInstance() is the simplest method for no-args constructors.

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

Sidebar

Related Questions

Why this code don't work,when i want run this code vwd 2008 express show
I want to run code which needs boost libraries. I built it using CMake.
i want to run the function Run in the main, but am not allowed
I have written php program and uploaded on server. I want run this program
I want to run wget as follows shell_exec('wget 'http://somedomain.com/somefile.mp4''); sleep(20); continue my code... What
Possible Duplicate: Calling virtual functions inside constructors Look at this code. In the constructor
This is my code which I had tried to run in my c# .net
I want run all script from the directory . Like , The directory contains
I want run a script as follows: runner: ssh 'java program &' ssh 'java
Want to run javascript function from parent window in child window Example I have

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.