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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T20:23:22+00:00 2026-06-05T20:23:22+00:00

I have two java classes as follows App1 without a package: class App1 {

  • 0

I have two java classes as follows

App1 without a package:

class App1 {
    public static void main(String[] args) {
        System.out.println("App1 hello world...");
    }
}

App2 in a package:

package java.java.package1;    
class App2 {
    public static void main(String[] args) {
        System.out.println("App2 hello world...");
    }
}

I can compile them both:

D:\javaTest>javac App1.java

D:\javaTest>javac App2.java

However, I can only run the first one:

D:\javaTest>java App1
App1 hello world...

D:\javaTest>java java.java.package1.App2

Exception in thread "main" java.lang.NoClassDefFoundError: java/java/package1/App2
Caused by: java.lang.ClassNotFoundException: java.java.package1.App2
        at java.net.URLClassLoader$1.run(Unknown Source)
        at java.security.AccessController.doPrivileged(Native Method)
        at java.net.URLClassLoader.findClass(Unknown Source)
        at java.lang.ClassLoader.loadClass(Unknown Source)
        at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)
        at java.lang.ClassLoader.loadClass(Unknown Source)
Could not find the main class: java.java.package1.App2.  Program will exit.

How can I run App2?

  • 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-05T20:23:23+00:00Added an answer on June 5, 2026 at 8:23 pm

    If you put the source in an appropriate directory hierarchy matching the package name (D:\javaTest\java\java\package1\App1.java), and compile/run from the root of the hierarchy (D:\javaTest), you wouldn’t have this problem:

    D:\javaTest>javac java\java\package1\App1.java
    
    D:\javaTest>java java.java.package1.App1
    App2 hello world...
    

    You can also compile using the -d option so that the classes are moved into such a directory hierarchy:

    javac -d . App2.java
    java java.java.package1.App2
    

    Note you shouldn’t use a package name starting with java, and later versions of the JDK will throw a SecurityException. See this question for more information.

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

Sidebar

Related Questions

I have two Java-Classes as follows: public class MyClass { ... } public class
In Java I have two classes: Class A { public String ID; public Object
I have two Java classes: B, which extends another class A, as follows :
I have two java classes. Schedule is the main class that uses an array
Thanks !!i have two .java classes as trial.java and CommonActivity.java as: public void onClick(View
I have two entities A and B: A.java: ... public class A implements Serializable
I have an entity class: Cabbage.java package womble; public class Cabbage { private int
I have written two simple Java classes (one of them containing main(), and the
Actually I have two java classes of which one is an activity class. Now
I'm making a shopping list mobile application (Java ME) and i have two classes;

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.