File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Beginning Java and the fly likes trouble running compiled file Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Java Interview Guide this week in the Jobs Discussion forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "trouble running compiled file" Watch "trouble running compiled file" New topic

trouble running compiled file

rick simpson

Joined: Oct 15, 2008
Posts: 8

I'm stumped. I've written a couple classes that work find in Eclipse. I've successfully compiled them. However when I try running the class with main, I get the following message:

Exception in thread "main" java.lang.NoClassDefFoundError: Echo (wrong name: Test/Echo)
at java.lang.ClassLoader.defineClass1(Native Method)
at java.lang.ClassLoader.defineClass(
at Method)
at java.lang.ClassLoader.loadClass(
at sun.misc.Launcher$AppClassLoader.loadClass(
at java.lang.ClassLoader.loadClass(
at java.lang.ClassLoader.loadClassInternal(
Could not find the main class: Echo. Program will exit.

When I'm in the dir with the Echo.class file, I'm typing java -cp . Echo

Any help and guidence appreciated.
Ernest Friedman-Hill
author and iconoclast

Joined: Jul 08, 2003
Posts: 24199

Assuming Echo.class is in a directory "Test":

cd ..
java -cp . Test.Echo

You need to let Java find the class from the root of the package hierarchy.

[Jess in Action][AskingGoodQuestions]
I agree. Here's the link:
subject: trouble running compiled file
It's not a secret anymore!