• Post Reply Bookmark Topic Watch Topic
  • New Topic

cannot find symbol?......wats happening???  RSS feed

 
saidon conteh
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Here is the malfunctioning code........

 
Rajkumar balakrishnan
Ranch Hand
Posts: 445
Android Eclipse IDE Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Do you have the classes like Head ,Arm and Legs in the same folder as of your Human program. If so then it's not going to show such errors. Then try to post those codes too.To check what you have done in it. Then please post your error message here to reduce the readers time.
 
fred rosenberger
lowercase baba
Bartender
Posts: 12563
49
Chrome Java Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
posting the EXACT error message would be a big help. without it, we don't know what symbol on what line. there is little to no advice we can give you.
 
saidon conteh
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The head, arms and legs are properties of the human class and are represented as separate objects. these objects are constructed from within the same package. Then in the main method of the human I have create an instance of a human and set the properties so that it looks like somebody.

Here are the errors im getting.....

>javac Human.java
Human.java:11: cannot find symbol
symbol : class Head
location: class Human
public Head myHead;
^
Human.java:12: cannot find symbol
symbol : class Arm
location: class Human
public Arm[] myArms = new Arm[2];
^
Human.java:13: cannot find symbol
symbol : class Leg
location: class Human
public Leg[] myLegs = new Leg[2];
^
Human.java:12: cannot find symbol
symbol : class Arm
location: class Human
public Arm[] myArms = new Arm[2];
^
Human.java:13: cannot find symbol
symbol : class Leg
location: class Human
public Leg[] myLegs = new Leg[2];
^
Human.java:27: cannot find symbol
symbol : class Head
location: class Human
myHead = new Head();
^
Human.java:28: cannot find symbol
symbol : class Arm
location: class Human
myArms[0] = new Arm("RightArm");
^
Human.java:29: cannot find symbol
symbol : class Arm
location: class Human
myArms[1] = new Arm("LeftArm");
^
Human.java:30: cannot find symbol
symbol : class Leg
location: class Human
myLegs[0] = new Leg("RightLeg");
^
Human.java:31: cannot find symbol
symbol : class Leg
location: class Human
myLegs[1] = new Leg("LeftLeg");
^
10 errors
 
Rajkumar balakrishnan
Ranch Hand
Posts: 445
Android Eclipse IDE Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Try compile with this command
javac -cp "C:\Program Files\Java\jre1.5.0_04\bin" <YourClass>.java

And the problem may be due to the classpath error. Check your classpath.
And do readthis article which might be clear you about the error. You may also find some good one's if you google "cannot find symbol error in java".
 
Campbell Ritchie
Marshal
Posts: 56546
172
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Rajkumar balakrishnan:
Try compile with this command

javac -cp "C:\Program Files\Java\jre1.5.0_04\bin" <YourClass>.java
No, don't use that command. Don't put any files in the bin folder, which should be reserved for classes from the Java API. Older versions of Java had their bin folder in the classpath, but that is no longer necessary.

Which folder have you got the Head Arm and Leg classes in?
Do they have a package declaration? In which case you will have to import them. Otherwise, Rajkumar Balakrishnan's first suggestion, to make sure the Head Arm and Leg classes are in the correct folder, will probably sort out your problem.
 
Rajkumar balakrishnan
Ranch Hand
Posts: 445
Android Eclipse IDE Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
No, don't use that command. Don't put any files in the bin folder, which should be reserved for classes from the Java API. Older versions of Java had their bin folder in the classpath, but that is no longer necessary.


I just denote that for an example and not force him to compile what exactly i type here. Just use the classpath instead of a one which i used there.Like

javac -cp "Your Class Path" <YourClass>.java
 
Campbell Ritchie
Marshal
Posts: 56546
172
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If (as you correctly suggested earlier) you have all your class files in the correct folder, there is no need to add a classpath. At the beginner's stage it is much easier to put all the classes in the same folder; such classes would be in the same package in a more advanced project anyway. In which case the default classpath of "." is all that is required.
 
saidon conteh
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ok. il try to shed more light on the issue.....

I am developing a class to represent a Human. The head, arms and legs should be properties of the human and should be represented by separate objects. All of the objects should have at least three properties and one method. The head, arms and legs can only be constructed from within the same package. The human should include a walk method that uses the legs to actually move. In the main method of the human, I have created an instance of a human and set the properties so that it looks like somebody. Produce a UML class diagram that explains how the classes relate to each other. Assume that relations between Human and Arm or Leg are compositions. Be careful creating your constructor in Human class. Understand well what composition means.....

This is what iv come up with. After debugging got two errors now....din know Java was this hard. Been at it from morning.

And the errors.....



 
Rajkumar balakrishnan
Ranch Hand
Posts: 445
Android Eclipse IDE Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
just change your code like this one.

public Arm[] myArms=new Arm[2];


I am not sure what you exactly meant by this piece of code

public Leg[] myLegs = new Leg[2]();



Because []() were not put at successive places.
 
saidon conteh
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Rajkumar balakrishnan:
just change your code like this one.

Because []() were not put at successive places.


When i do that, i get this errors...

 
Campbell Ritchie
Marshal
Posts: 56546
172
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Minor disagreement: it should read

private Leg[] myLegs = new Leg[2]; and similar.

I presume you have the Leg Head and Arm classes already? You ought to test them first. Let's have a LegTest class . . . When you have run that class, you can see that the Leg is working. Similarly for Arm and Head.

The System.out.... l) bit calls the toString() method in the Leg object. If you haven't overridden toString() you will get something like Leg@1234abcd.
 
Campbell Ritchie
Marshal
Posts: 56546
172
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Put the Human class aside and get the Leg Arm and Head classes working first.
 
Rajkumar balakrishnan
Ranch Hand
Posts: 445
Android Eclipse IDE Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I agree with Campbell Ritchie.. Just do compile your Arms, Legs and whatever other classes you used here. Then try to compile it . It surely works. A cannot find symbol instead tell you that it can't find such a symbol or class or whatever is missing.
 
saidon conteh
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Rajkumar balakrishnan:
I agree with Campbell Ritchie.. Just do compile your Arms, Legs and whatever other classes you used here. Then try to compile it . It surely works. A cannot find symbol instead tell you that it can't find such a symbol or class or whatever is missing.


Hi all....
Thanks for your help guys...appreciate it. Here are the Human, Arm, Leg and Head classes. Tiz now working ok.

Human.java


class Head


class Arm


class Leg
 
Campbell Ritchie
Marshal
Posts: 56546
172
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Well done. Just one thing: make access to the Arm and Leg objects in the Human class private. You don't want outside code altering them while you're not watching.
 
saidon conteh
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Campbell Ritchie:
Well done. Just one thing: make access to the Arm and Leg objects in the Human class private. You don't want outside code altering them while you're not watching.


Ok. i will and post tomorrow. Thanks
 
saidon conteh
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by saidon conteh:


Ok. i will and post tomorrow. Thanks


question though. how can I use constructors to set properties of leg,head,arm classes?
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!