File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
Win a copy of Clojure in Action this week in the Clojure forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

cannot find symbol

 
Sami Devine
Ranch Hand
Posts: 44
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi, I am working on an excercise about access control. I have the following as a single file. During compilation I get the error "cannot find symbol" method:No1.



 
Kyle Kroboth
Greenhorn
Posts: 2
Android Java Ubuntu
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.

 
Sami Devine
Ranch Hand
Posts: 44
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Deep Purohit
Greenhorn
Posts: 9
Eclipse IDE Flex Java
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You seem to have caught into the regular classpath problem. Check out - http://download.oracle.com/javase/tutorial/getStarted/problems/index.html
If the problem persist then revert.
 
Peeyush Bhadola
Greenhorn
Posts: 10
Chrome Java Windows
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
C:\moose>javac Noose.java

Step 5. Run your program
C:\moose>java moose.Noose
 
Campbell Ritchie
Sheriff
Pie
Posts: 47293
52
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
c:\ myJava:> javac moose/Noose.java
c:\myJava:> java moose.Noose
If there is no system classpath, then the java tool will use "." as its classpath.

. . . and welcome to the Ranch
 
Peeyush Bhadola
Greenhorn
Posts: 10
Chrome Java Windows
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
@Campbell - Yes ... I was wrong. Thanks
 
Sami Devine
Ranch Hand
Posts: 44
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Campbell Ritchie
Sheriff
Pie
Posts: 47293
52
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
[campbell@campbell1110 java]$
 
I agree. Here's the link: http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic