*
The moose likes Beginning Java and the fly likes Why cant I create this object? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Why cant I create this object?" Watch "Why cant I create this object?" New topic
Author

Why cant I create this object?

Joe Degler
Greenhorn

Joined: Oct 10, 2011
Posts: 20
I have the book "Head First" in the german version, I'm through to page 200 and I just wanted to check something, if it's gonna work, and to test my own knowledge.
I wrote this simple piece of code, first of all it didn't work in any way, then I added "public static void main (String[] args) {" and I suddenly had less errors, but now there are only 2 left, and they both point at the point where I want to create the object, but I fail to see where the problem is. Any help?




Thanks in advance, Joe
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61095
    
  66

It's usually a good idea to post the exact wording of the errors.

P.S. Welcome to the Ranch.


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
Joe Degler
Greenhorn

Joined: Oct 10, 2011
Posts: 20
There you go:

Testobjekt.java:4: error: cannot find symbol
Hund h = new Hund();
^
symbol: class Hund
location: class Testobjekt
Testobjekt.java:4: error: cannot find symbol
Hund h = new Hund();
^
symbol: class Hund
location: class Testobjekt
2 errors

Replace "Hund" with "Dog" and "Testobjekt" with "Testobject"
fred rosenberger
lowercase baba
Bartender

Joined: Oct 02, 2003
Posts: 11256
    
  16

You don't have the code posted for the Dog class. Do you have code for it? Have you compiled it?


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

Joined: Oct 10, 2011
Posts: 20
That is the Dog class, but the German version of it, as I wrote "Think of "Hund" as "Dog" and so on, because I wasnt sure if translating the names would break it, but give me a second, I'll do something:


Testobject.java:4: error: cannot find symbol
Dog d = new Dog();
^
symbol: class Dog
location: class Testobject
Testobject.java:4: error: cannot find symbol
Dog d = new Dog();
^
symbol: class Dog
location: class Testobject
2 errors

There you have the english version of it!
Stefaan Dutry
Ranch Hand

Joined: Sep 17, 2010
Posts: 32

The error is basicaly saying that your compiler can not locate the class with the name Dog.

Do you have a class named Dog somewhere?

How exactly are you trying to compile/run your code?
(in an editor, with a command, if so which command)?
Joe Degler
Greenhorn

Joined: Oct 10, 2011
Posts: 20
There seems to be the problem, I dont want the little code to GO to the class Dog, I want to to CREATE a OBJECT called Dog.
I'm using the Command line of Windows... But I write it in the Notepad, and then compile it in the Command line...
Jeff Kendall
Greenhorn

Joined: Aug 19, 2011
Posts: 4
As you have it you are trying to instantiate a class called Dog that doesn't exist because you haven't made it. If you just want an object that contains "Dog" then you can do this.


Replace:
Dog d = new Dog();
With:
String d = "Dog";
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 38483
    
  23
As people have already said: where is your Dog/Hund class?
Joe Degler
Greenhorn

Joined: Oct 10, 2011
Posts: 20
Thank you, and of course the other too, that solved it for me.

Final Code (if anyone ever needs it):



- resolved -
Stefaan Dutry
Ranch Hand

Joined: Sep 17, 2010
Posts: 32

according to page 200 of Head First Java, i think he wants to create an actual Dog object.

The best way to do it would be to make a class Dog first. Something like the following should do for a learning test I suppose:

in a file named Dog.java:


The compiler doesn't know what a "Dog" is, or what methods it has, unless you tell him by providing the Dog class.
Joe Degler
Greenhorn

Joined: Oct 10, 2011
Posts: 20
Thank you for your effort Stefan, but I've got a German version, and the page 200 wasnt 100% correct, it was acutally 209, and while I was reading about .equal() I made myself the little challenge to create the simple code shown above, to be sure I understood it right.
 
wood burning stoves
 
subject: Why cant I create this object?