Win a copy of The Java Performance Companion this week in the Performance forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

cannot find symbol

 
Naga Nagesh
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi, I am getting this error: "cannot find symbol"

These are the classes I wrote...

public class DogTestDrive
{
public static void main(String[] args)
{
Doggy d = new Doggy();
d.size = 40;
d.bark();
}

}

.....
public class Doggy
{
int size;
String breed;
String name;
void bark()
{
if(size > 60)
{
System.out.println("Ruff Ruff");
}
else
{
System.out.println("Ding Ding");
}
}
}

Please help..I am trying to get my hands on java..Thanks in advance.
 
Rob Spoor
Sheriff
Pie
Posts: 20552
57
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
"Nagesh B",

Please read your private messages regarding an important announcement.

Thank you,

Rob


Also, please Use Code Tags. And finally, Tell The Details. What is the exact message? Which symbol can't it find?

I've just tried to compile the code you've posted here, and there was no problem at all.
 
fred rosenberger
lowercase baba
Bartender
Posts: 12147
31
Chrome Java Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The error message tells you exactly what symbol it cannot find. that's a big clue into solving your problem. a quick eyeball of your code doesn't have anything pop out as to the problem.
 
Shashank Agarwal
Ranch Hand
Posts: 105
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I'm assuming that you're getting the error at

In class Doggy, declare size as public -

That might solve it!
 
Campbell Ritchie
Sheriff
Pie
Posts: 49447
62
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Unlikely that is the problem if the two are in the same folder. Besides it is bad design to have public fields, or to set them like d.size = 40;
 
Campbell Ritchie
Sheriff
Pie
Posts: 49447
62
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
There appears to be no compiler error in the code posted. Read this FAQ.
 
Shashank Agarwal
Ranch Hand
Posts: 105
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Campbell Ritchie:
Unlikely that is the problem if the two are in the same folder. Besides it is bad design to have public fields, or to set them like d.size = 40;


Yup. Recommend adding a getter and setter.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic