The problem is in the main method in the Noose class. you creating a new object of Noose and calling the method No1() but there is no No1() method in the Noose Class. you need to create in instance of Monkey to access those methods.
So it looks like this.
Joined: Jan 30, 2011
Hi Kyle, thanks I had actually tried a few things. I tried by changing the code as follows:
I renamed the program as Noose.java When I do a java Noose, I get NoClassDef found error - wrong name moose/Noose. javac Noose.java compiles fine.
Hello Sami, I think you forgot to set the CLASSPATH variable, which is the most important activity to be performed while playing with packages. Here are the steps that can avoid NoClassDefFoundError :
Step 1. Create your program. (In your case it is Noose.java)
Step 2. Now put this file in a folder with name same as your package name. (In your case, the package name is moose). So you need to create a directory or folder with folder name as moose, and then put your noose.java inside this folder.
Step 3. [Main Step] Now set the CLASSPATH. Consider you are working on Windows and your newly created folder moose is present under C:\ directory. If this is the case then you need to set CLASSPATH using command prompt as: set CLASSPATH=.;C:\; When you set classpath, Java will search our file in C-directory and also in current directory. This is because I have used .(dot) for current directory and C:\ for C directory.
Step 4. Compile the java file
Step 5. Run your program
Peeyush Bhadola wrote:Hello Sami, I think you forgot to set the CLASSPATH variable, which is the most important activity to be performed while playing with packages. . . .
No, setting the classpath is not at all important. You should almost certainly NOT set a system classpath. A system classpath can cause more trouble than it solves. Note the advice given in that Java™ Tutorials link was to unset the classpath.
You should be executing your application from the root of the package structure. so if you have a class called moose.Noose and the moose directory is inside the myJava folder, then you should set your command line to the myJava folder
Hi Campbell, this still does not work. I have set the command prompt to my package C:\Java\Moose>. To clarify, there is a moose folder in the Java folder. The .java file is in the moose folder.
Joined: Oct 13, 2005
Sorry I didn't look at your query last night.
All right, so I am not using Windows®, but it would work exactly the same way on any operating system. And I have no classpath set
[campbell@campbell1110 ~]$ cd java
[campbell@campbell1110 java]$ mkdir moose
[campbell@campbell1110 java]$ cd moose
[campbell@campbell1110 moose]$ gedit Noose.java
[campbell@campbell1110 moose]$ cd ..
[campbell@campbell1110 java]$ javac moose/Monkey.java
javac: file not found: moose/Monkey.java
Usage: javac <options> <source files>
use -help for a list of possible options
[campbell@campbell1110 java]$ javac moose/Noose.java
[campbell@campbell1110 java]$ java moose.Noose
This is monkey
I’ve looked at a lot of different solutions, and in my humble opinion Aspose is the way to go. Here’s the link: http://aspose.com