Win a copy of The Little Book of Impediments (e-book only) this week in the Agile and Other Processes forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Why cant I create this object?

 
Joe Degler
Greenhorn
Posts: 20
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Pie
Posts: 65340
97
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It's usually a good idea to post the exact wording of the errors.

P.S. Welcome to the Ranch.
 
Joe Degler
Greenhorn
Posts: 20
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 12266
36
Chrome Java Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You don't have the code posted for the Dog class. Do you have code for it? Have you compiled it?
 
Joe Degler
Greenhorn
Posts: 20
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 32
Eclipse IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 20
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 51453
87
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
As people have already said: where is your Dog/Hund class?
 
Joe Degler
Greenhorn
Posts: 20
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 32
Eclipse IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 20
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic