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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 19, 20262026-05-19T22:28:32+00:00 2026-05-19T22:28:32+00:00

I made a really simple java example with two files: Dog.java contains: package com.greg.dog;

  • 0

I made a really simple java example with two files:

Dog.java contains:

package com.greg.dog;

public class Dog {
    public void bark() {
        System.out.println("bark");
    }
}

TestDog.java contains:

package com.greg.dog;

public class TestDog {
   public static void main(String args[]) {
        Dog d = new Dog();
        d.bark();
    }
}

I have these two files in the location ~/Desktop/test/src/com/greg/dog

When I compile them, Dog.java compiles fine, but TestDog.java can’t find my Dog class:

user1@blackpearl:~/Desktop/test/src/com/greg/dog$ javac Dog.java 
user1@blackpearl:~/Desktop/test/src/com/greg/dog$ javac TestDog.java 
TestDog.java:6: cannot find symbol
symbol  : class Dog
location: class com.greg.dog.TestDog
        Dog d = new Dog();
        ^
TestDog.java:6: cannot find symbol
symbol  : class Dog
location: class com.greg.dog.TestDog
        Dog d = new Dog();
                    ^
2 errors

I’m on Ubuntu, here’s all the java information:

java version "1.6.0_0"
IcedTea6 1.3.1 (6b12-0ubuntu6.7) Runtime Environment (build 1.6.0_0-b12)
OpenJDK 64-Bit Server VM (build 1.6.0_0-b12, mixed mode)

Any ideas what I could be doing wrong? Do I need to import Dog.java? Am I doing packages wrong?

Update

Per Anon’s suggestion, I changed directories to the src directory and everything compiles. However when I go to run TestDog.java I get this error:

user1@blackpearl:~/Desktop/test/src$ java com/greg/dog/TestDog.java 
Exception in thread "main" java.lang.NoClassDefFoundError: com/greg/dog/TestDog/java
Caused by: java.lang.ClassNotFoundException: com.greg.dog.TestDog.java
    at java.net.URLClassLoader$1.run(URLClassLoader.java:217)
    at java.security.AccessController.doPrivileged(Native Method)
    at java.net.URLClassLoader.findClass(URLClassLoader.java:205)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:319)
    at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:294)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:264)
    at java.lang.ClassLoader.loadClassInternal(ClassLoader.java:332)
Could not find the main class: com/greg/dog/TestDog.java. Program will exit.
  • 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-19T22:28:33+00:00Added an answer on May 19, 2026 at 10:28 pm

    The Java compiler expects other classes to be in the package-appropriate directory relative to where the compiler is invoked from.

    You’ll want to be compiling using something like:

    user1@blackpearl:~/Desktop/test/src$ javac com/greg/dog/Dog.java
    user1@blackpearl:~/Desktop/test/src$ javac com/greg/dog/TestDog.java
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

What is the really minimal example of Silverlight application? For example, I made the
I made a class that derives from Component: public class MyComponent: System.ComponentModel.Component { }
I have a site I made really fast that uses floats to display different
I made a class from Linq to SQL Clasees with VS 2008 SP1 Framework
I made a Java Applet with some Standard GUI Components on it. I used
I made an html file called test.html then I navigated to it as http://site.com/test.html?test1=a
I think this explains my question well enough: public class Model { public static
ASP.NET MVC makes it really easy to create editing templates for simple, flat objects.
I want to make a simple program. Don't really care what it does, actually.
Made solution change: I am trying to display a html table of data.. In

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.