cannot find symbol?......wats happening???

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.

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.

There are only two hard things in computer science: cache invalidation, naming things, and off-by-one errors

saidon conteh

Greenhorn

Posts: 10

posted 9 years ago

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.

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".

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.

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

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

posted 9 years ago

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.

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

posted 9 years ago

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

posted 9 years ago

Put the Human class aside and get the Leg Arm and Head classes working first.

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.

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

posted 9 years ago

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

posted 9 years ago

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

posted 9 years ago

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?