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 (PkgInterface.java and UsePkgInterface.java) are as follows:
This is my current CLASSPATH: CLASSPATH=C:\Applications\Java;C:\j2sdk1.4.1_01 I issued the following commands to compile the source code from the C:\Applications\Java directory: javac -d . com\neapco\source\PkgInterface.java javac -d com\neapco\classes com\neapco\source\UsePkgInterface.java 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 ]
Joined: Jan 23, 2003
Sorry...should have put the directory structure inside a <Code> block to keep the formatting. Here it is in a more verbose format: C:\Applications\Java\com\neapco\classes C:\Applications\Java\com\neapco\interfaces C:\Applications\Java\com\neapco\source Sorry for the confusion...
Joined: Nov 04, 2001
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.. regards maulin
Maulin, That solved it! Thanks for your help! Some days, it's best not to get out of bed. Thanks again!
Joined: Dec 10, 2001
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!