Win a copy of Programmer's Guide to Java SE 8 Oracle Certified Associate (OCA) this week in the OCAJP forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

cannot find symbol

 
sahar sa
Ranch Hand
Posts: 102
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Dear friend,
I have a class and I want to use a method from another class. e.g.: I want to call method X of class A from inside of class B.
So I write A.x() inside class B. I also import package.A inside of class B. but it throws me this error:

DB is the package name, DbHistory is the class name and PsUpdate is the method name:

I dont know how netbean can not recognize it because when I wrote "Db." netbean automatically gave me the method name "PsUpdate"!!
do you know what is wrong?

Thanks,
Sahar.
 
Henry Wong
author
Marshal
Pie
Posts: 21385
84
C++ Chrome Eclipse IDE Firefox Browser Java jQuery Linux VI Editor Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
sahar sa wrote:
I dont know how netbean can not recognize it because when I wrote "Db." netbean automatically gave me the method name "PsUpdate"!!
do you know what is wrong?


Is PsUpdate() a static method? Because if it isn't, you can't call it without an instance.

Henry
 
Rob Spoor
Sheriff
Pie
Posts: 20606
60
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It isn't complaining about PsUpdate, it thinks that DB.DbHistory is a field of class DB instead of class DbHistory inside package DB. The problem is your class name; it is called DB as well. So DB is the package but also the class name. The compiler will use the nearest scope, and that is the class.

Change your package name from DB to db and your problem will go away.
 
sahar sa
Ranch Hand
Posts: 102
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks, problemo solved!
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic