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 Problem calling a simple program Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Make it so: Java DB Connections & Transactions this week in the JDBC forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Problem calling a simple program" Watch "Problem calling a simple program" New topic

Problem calling a simple program

Tim Oister

Joined: Jan 23, 2003
Posts: 11
I created a simple program to call an interface and have everything compiled an in the right directories, but for some reason I can't get the program to run. Here's what I have starting with the directory structure:

The two programs that I compiled ( and are as follows:

This is my current CLASSPATH:
I issued the following commands to compile the source code from the C:\Applications\Java directory:
javac -d . com\neapco\source\
javac -d com\neapco\classes com\neapco\source\
I end up with the PkgInterface.class file in the com\neapco\interfaces directory as expected, and the UsePkgInterface.class file in the com\neapco\source directory.
I try running the program from C:\Applications\Java, but get an error as follows:
>java com.neapco.classes.UsePkgInterface
Exception in thread "main": java.lang.NoClassDefFoundError: com/neapco/classes/UsePkgInterface (wrong name: UsePkgInterface)
I've tried running the program from the classes directory, replacing the '.' with '/' when I try to run it, but to no avail. How can I get this to run, and is there some default location that I should be running this program from?
As you can see, these programs aren't rocket science, but any help would be greatly appreciated!
[ edited to preserve formatting using the [code] and [/code] UBB tags -ds ]
[ June 29, 2003: Message edited by: Dirk Schreckmann ]
Tim Oister

Joined: Jan 23, 2003
Posts: 11
Sorry...should have put the directory structure inside a <Code> block to keep the formatting.
Here it is in a more verbose format:
Sorry for the confusion...
Maulin Vasavada
Ranch Hand

Joined: Nov 04, 2001
Posts: 1873
hi Tim
UsePkgInterface.class file in the com\neapco\source directory

statment seems to be incorrectly written. because, u r compiling as,
javac -d ...\classes right??
also, the problem is,
in the UsePkgInterface class u don't have "package com.neapco.classes" statement which means the class is in the "default" package not in any particular one and u r tring to run as if that class is in "com.neapco.classes" package.
put package com.neapco.classes and see if u r able to run it..
Tim Oister

Joined: Jan 23, 2003
Posts: 11
That solved it! Thanks for your help! Some days, it's best not to get out of bed.
Thanks again!
Dirk Schreckmann

Joined: Dec 10, 2001
Posts: 7023
Some days, it's best not to get out of bed.
Bah! Just imagine you hadn't gotten out of bed and asked your question at JavaRanch. Maulin wouldn't have helped you out and you still be stuck.
Some days, it's best to get out of bed and hang out in the Saloon!

[How To Ask Good Questions] [JavaRanch FAQ Wiki] [JavaRanch Radio]
I agree. Here's the link:
subject: Problem calling a simple program
It's not a secret anymore!