wood burning stoves 2.0*
The moose likes Beginning Java and the fly likes cannot find symbol 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" Watch "cannot find symbol" New topic
Author

cannot find symbol

sahar sa
Ranch Hand

Joined: Jul 06, 2009
Posts: 102
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
Sheriff

Joined: Sep 28, 2004
Posts: 18760
    
  40

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


Books: Java Threads, 3rd Edition, Jini in a Nutshell, and Java Gems (contributor)
Rob Spoor
Sheriff

Joined: Oct 27, 2005
Posts: 19680
    
  19

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.


SCJP 1.4 - SCJP 6 - SCWCD 5 - OCEEJBD 6
How To Ask Questions How To Answer Questions
sahar sa
Ranch Hand

Joined: Jul 06, 2009
Posts: 102
Thanks, problemo solved!
 
 
subject: cannot find symbol