aspose file tools*
The moose likes Beginning Java and the fly likes symbol not found error Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Java 8 in Action this week in the Java 8 forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "symbol not found error" Watch "symbol not found error" New topic
Author

symbol not found error

Keith Stansbie
Greenhorn

Joined: Apr 25, 2006
Posts: 10
I have a small exercise consisting of a person as one class who has arms, legs and a head, each as a separate class. The person is built up of the other classes.

Each of the classes - arm, leg and head - complies separately but when it comes to Human, I get lots of symbol not found errors.

The human contains the correct constructors (as far as I can see) and the classes are all in the same package so what is up?

I have looked up this error on the Sun forum and someone there posted something similar. Turned out to be a classpath issue as he had recently installed Quicktime. I have checked my classpath and it SEEMS fine (to a novice like me).

Anything I can do to make sure that my person finds his limbs?

K
Paul Sturrock
Bartender

Joined: Apr 14, 2004
Posts: 10336

Can you post your code?


JavaRanch FAQ HowToAskQuestionsOnJavaRanch
Jesper de Jong
Java Cowboy
Saloon Keeper

Joined: Aug 16, 2005
Posts: 13884
    
  10

Things to check:

- Is your classpath set correctly?
- Are the classes that you reference present in the correct directory?
- Java is case sensitive; did you write names with a different case than they should be?
- Did you make a typo somewhere?


Java Beginners FAQ - JavaRanch SCJP FAQ - The Java Tutorial - Java SE 7 API documentation
Scala Notes - My blog about Scala
Bob Ruth
Ranch Hand

Joined: Jun 04, 2007
Posts: 320
And make sure that you are calling constructors/methods that have a matching signature..... so that overloading isn't getting to you unexpectedly. (i.e. if you define a method with a particular set of arguments and then call it with one of the arguments of the wrong type, it will complain that symbol can not be found because it can't find the method name with the combination of arguments that you specified on the call.


------------------------
Bob
SCJP - 86% - June 11, 2009
Keith Stansbie
Greenhorn

Joined: Apr 25, 2006
Posts: 10
Before the code, firstly, thanks for all of the prompt replies.

Next, I reckon that my classpath is correct. Path points to the only place I keep code and classpath is to the version of java I am using.

Firstly, arm:

/**
*Author Keith Stansbie
*A simple class to make arms for the human
**/
import java.util.*;

public class Arm{
boolean side; //true is right, false is left
int nailLength; //length of nails
boolean tan; //is arm tanned?

protected Arm(boolean side, int nailLength, boolean tan){
this.side = side;
this.nailLength = nailLength;
this.tan = tan;
}

//Method to grow nails

public void nailgrow(){
nailLength++;
}
}

Next, leg:

/**
*Author Keith Stansbie
*A simple class to make legs for the human
**/

import java.util.*;

public class Leg{
boolean side; //true is right, false is left
int location; //position of leg
int length; //length of leg

protected Leg(boolean side, int location, int length){
this.side = side;
this.location = location;
this.length = length;
}

//Method to move leg

public void move(){
location++;
}
}

Now a head:

/**
* @author Keith Stansbie
* A simple class to make a new head for the humam
**/

import java.util.*;

public class Head{
String eyeColour;
String hairColour;
boolean piercedEar;

/**
* @param EyeColour the colour of the eyes.
* @param HairColour the colour of the hair.
* @param Set piercedEar to true or false.
**/

protected Head(String eyeColour, String hairColour, boolean piercedEar){
this.eyeColour = eyeColour;
this.hairColour = hairColour;
this.piercedEar = piercedEar;
}
}

And this is the Human:

/**
* A simple class to make a human
*@author Keith Stansbie
**/

import java.util.*;
import java.io.*;

public class Human{
public Head head;
public Arm rightArm;
public Arm leftArm;
public Leg rightLeg;
public Leg leftLeg;

public Human(Head myHead, Arm myLeftArm, Arm myRightArm, Leg myLeftLeg, Leg myRightLeg){
this.head = myHead;
this.rightArm = myRightArm;
this.leftArm = myLeftArm;
this.leftLeg = myLeftLeg;
this.rightLeg = myRightLeg;
}

public void walk(int step){
for(int j=0; j<=step; j++){
// Call the move method from the Leg class.
leftLeg.move();
rightLeg.move();
}
}

public static void main(String[] args){
/**
* This makes new arms,legs and head classes
**/
Head myHead = new Head("Blue","Grey",true);
Arm myLeftArm = new Arm(true,6,false);
Arm myRightArm = new Arm(true,6,false);
Leg myLeftLeg = new Leg(false,0,9);
Leg myRightLeg = new Leg(false,0,9);
/**
* Make a new Human Class and add the arms,legs,and head object
* to the human class
**/
Human me = new Human(myHead,myLeftArm,myRightArm,myLeftLeg,myRightLeg);
}
}

All 4 classes are in the same package inside the folder where I keep my code. I have tried with the package statement at the start of each to no effect. I have checked the filename of each class and they are Leg, Arm, Head (all of which compile, BTW) and Human. All.java and all capitalised.

Sorry if the formatting is mucked up with the copy/paste.

Also apologies for the long post - but i was asked for the code

FWIW, I think that it is one of those glaringly ridiculous errors that only one who has spent days looking (as I have) could possibly miss

K
Shyam Prasad Murarka
Ranch Hand

Joined: May 02, 2005
Posts: 209
Dear Keith Stansbie,
First of all, you can enclose your code within code tags to preserve your formatting.
Secondly, I copied-pasted all your programs and did NOT get any compile errors. I did not specify any package names to avoid package-related hassles.
So, if you are using packages, then there might be something you might be missing over there.
Thirdly, you mentioned:

Next, I reckon that my classpath is correct. Path points to the only place I keep code and classpath is to the version of java I am using.


Shouldn't that be the other way round? Path should be pointing to your Java version and classpath to your source files. I may be wrong. But on my machine Path is set to my Java version.

Fourthly, please do post the compile errors that you are getting.

Note: While posting a message, you will see Instant UBB Code tags listed below the Text Area. You can select the Code tag to enclose your code.


With Best Regards,
Shyam Prasad Murarka
Keith Stansbie
Greenhorn

Joined: Apr 25, 2006
Posts: 10
If there was a smiley for a red face, I would post it.

Yes, the path is Java version - sorry for the error.

Otherwise, it is still giving me the symbol not found.

K
Keith Stansbie
Greenhorn

Joined: Apr 25, 2006
Posts: 10


This is the first of the errors. I get 20 in total

K
Bob Ruth
Ranch Hand

Joined: Jun 04, 2007
Posts: 320
I built it and ran it with no problems too. I even made it walk.
Keith Stansbie
Greenhorn

Joined: Apr 25, 2006
Posts: 10
I am very happy to hear it!

I would love to know why it doesn't for me

Thanks for all the replies.

K
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: symbol not found error
 
Similar Threads
rowset
Error compiling the AdviceClient.java
cannot find symbol?......wats happening???
Servlet Compilation
importing classes into java programs