*
The moose likes Beginning Java and the fly likes cannot find symbol class Dog Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "cannot find symbol class Dog" Watch "cannot find symbol class Dog" New topic
Author

cannot find symbol class Dog

Bryan Peach
Ranch Hand

Joined: Sep 08, 2009
Posts: 76
Please help. I have to create a class Dog and then implement a driver for that class. I have done both and am now trying to test both but when i go to compile the driver I get this message :cannot find symbol class Dog. I am not sure how to delcare another class, or how to import the class Dog or whatever it is i have to do. Please Help. here is the code...

Driver:


Class:


I know this is probably really simple to fix... but I'm lost..
Mark Vedder
Ranch Hand

Joined: Dec 17, 2003
Posts: 624

Bryan Peach wrote:Please help. I have to create a class Dog and then implement a driver for that class. I have done both and am now trying to test both but when i go to compile the driver I get this message :cannot find symbol class Dog. I am not sure how to delcare another class, or how to import the class Dog or whatever it is i have to do. Please Help. here is the code...


Since Dog and DogDriver are both part of the Pet package, you do need an import statement for Dog in the DogDriver class. Based on what I am seeing in the sample code you posted, you should not be getting the particular error -- cannot find symbol class Dog -- that you are getting. There are some other issues looming, but lets get you past this one first.

Are both your Dog.java and DogDriver.java files saved in a directory named Dog?

If not, they both need to be in that directory. If that is okay, can you post the command that you are using to compile along with the directory you in when you try to compile.
Bryan Peach
Ranch Hand

Joined: Sep 08, 2009
Posts: 76
The file are both part of the same workspace and both projects are in the same Pet folder. Is that what you mean? I am using JCreator. and when i try to move DogDriver into the Dog file it says i have an invalid file path??? i'm lost
Bryan Peach
Ranch Hand

Joined: Sep 08, 2009
Posts: 76
ok i think i go that working.... but now i get invalid method declaration; return type required... and invalid method declaration; return type required public Date(int newDay, int newMonth, int newYear) errors in my Dog Class
Mark Vedder
Ranch Hand

Joined: Dec 17, 2003
Posts: 624

I'm not familiar with JBuilder. But it sounds like your problem is more with how to use that IDE than it is with how to code java. That is one reason I, along with many others, am a proponent of not using an IDE when first learning to program. You spend more time learning the tool than programming. Or you can't tell what are problems with the tool and what are problems with your code.

That being said, I'll see what I can do to help. Maybe someone else that knows JBuilder can jump in as well.

Have you tried compiling your code using the command line to see what happens?

What do yo mean by "when i try to move DogDriver into the Dog file"? I'm not understanding why you are trying to "move" DogDriver into the Dog file. By move, do you mean dragging the DogDriver file into the Dog file? The two classes should be in separate files. While you could put them in the same file under certain circumstances, doing such is a little beyond where you are I believe in your programming experience.

<edit>
Sorry, I was tying my reply to your first reply when yo posted your second. I'll answer that one now.
Bryan Peach
Ranch Hand

Joined: Sep 08, 2009
Posts: 76
yeah i got that figured out and working now... but now at my date constructor it is saying that its an invalid method declaration.... but its not even a method declaration... do you see whats wrong with it? Constructors really boggle my mind
Mark Vedder
Ranch Hand

Joined: Dec 17, 2003
Posts: 624

Bryan Peach wrote:yeah i got that figured out and working now... but now at my date constructor it is saying that its an invalid method declaration.... but its not even a method declaration... do you see whats wrong with it? Constructors really boggle my mind


A constructor is for constructing, or creating a new instance of, a particular class. The constructor exists within the same class and is named the same thing as the class. So your Dog class has Dog constructors, and can only have Dog constructors. Anything else in the class is a method. You cannot have a Date constructor in your Dog class. And there is no reason you ever should. What does a Dog know about creating a Date? A Dog can only know how to create himself. A Cat only knows how to create, or construct, a Cat, not a Dog. So a Cat cannot have a Dog constructor. And a Date only knows how to create a Date.

Now if a Dog needs to use a Date, the Dog class calls the Dog class' constructor. The Dog class goes not declare a Date constructor, it calls the Date constructor that resides in the Date class. That call can occur in a number of places, such as in the Dog's constructor itself, or in a method within the Dog class. Unfortunately, creating dates is a little more complex that if you want to create a Date other than today, you create a date trough a Calendar.

Do you really need a Date, with a day, month, and year? or do you just need the age (an int)? I ask since I see your Dog constructor is taking an int, which can be used to represent the Dog's age, but not a date.
Bryan Peach
Ranch Hand

Joined: Sep 08, 2009
Posts: 76
oh ok... that makes perfect sense..thanks for explaining that to me... so i have one more question... I have to create this Dog class and then two Sub-classes called WorkingDog and PetDog... How do i link them? just by having them in the same package? And the idea is if its a working dog i have to get certain information, but if its a pret dog i need different information... where would i make the distinction to branch off into either of the two subclasses and how do i make the distinction?
Bryan Peach
Ranch Hand

Joined: Sep 08, 2009
Posts: 76
Also now in my Class when I go to compile it is giving me missing method body, or declare abstract, and return outside method errors... any idea what that is about? here is the updated code.
Bryan Peach
Ranch Hand

Joined: Sep 08, 2009
Posts: 76
hahaha ok stupid me... i got the errors figured out. Now this is the last thing... I promise... in my driver is it saying that: cannot find symbol constructor Dog()... Whats that all about?
Mark Vedder
Ranch Hand

Joined: Dec 17, 2003
Posts: 624

Bryan Peach wrote:I have to create this Dog class and then two Sub-classes called WorkingDog and PetDog... How do i link them? just by having them in the same package?


No, sinply putting them in the same package will not result in them being subclasses. Think about it logically... how would the compiler know that PetDog is a subclass of Dog and not the other way around? There is nothing telling the compiler of such a relationship. The keyword extends is used to create a subclass:




Bryan Peach wrote:
And the idea is if its a working dog i have to get certain information, but if its a pret dog i need different information... where would i make the distinction to branch off into either of the two subclasses and how do i make the distinction?


Anything that is common to all Dogs goes in the Dog class. Since a PetDog extends Dog, it knows everything a Dog knows (there's a bit more detail involved in this, but for know, you can work off that statement.) Anything specific only to a pet dog goes in the PetDog class. And anything specific to a working dog class goes into the WorkingDog class.


Bryan Peach wrote:
hahaha ok stupid me... i got the errors figured out. Now this is the last thing... I promise... in my driver is it saying that: cannot find symbol constructor Dog()... Whats that all about?


In your Dog class, you only have a constructor Dog(String, Double, String, int) but in your DogDriver class you are trying to call the no-arg (i.e. no argument) constructor Dog(). So you either need to call the correct constructor in your DogDriver class (the one that takes all the information needed to construct a dog) or you need to add a no argument constructor to the Dog class. I think, based on what I am seeing in your code, you want to do the first thing.
Bryan Peach
Ranch Hand

Joined: Sep 08, 2009
Posts: 76
ok i'll just focus on one thing at a time here... i called the constructor like you just said and it is giving me an error now saying that .class is expected somewhere in the constructor call. here is the updated driver code.
Mark Vedder
Ranch Hand

Joined: Dec 17, 2003
Posts: 624

Dog(String, Double, String, int) is the signature of the constructor. It is saying the constructor takes those types. Your actual constructor, in your original post, was:

See how the types line up in the signature I posted?

When you call the constructor, you need to pass in actual values:
Bryan Peach
Ranch Hand

Joined: Sep 08, 2009
Posts: 76
Thats great... Thank you so much for all your help. I would be so lost right now.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: cannot find symbol class Dog
 
Similar Threads
Erronous Output
how to test the setter methods
Linking multiple classes
variables not found with OOP
learning how to use classes