aspose file tools*
The moose likes Java in General and the fly likes Cannot find symbol Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Java 8 in Action this week in the Java 8 forum!
JavaRanch » Java Forums » Java » Java in General
Bookmark "Cannot find symbol" Watch "Cannot find symbol" New topic
Author

Cannot find symbol

John Paterson
Ranch Hand

Joined: Mar 12, 2012
Posts: 116
Hi Folks,

Some issue I am having with some code I wrote. The code as follow:



I am getting a 'Cannot find symbol' error that says srch can't be found. Why am I getting this error? srch is declared in the constructor already so why this error? Hope someone can advise. Thanks.

regards
John
Kemal Sokolovic
Bartender

Joined: Jun 19, 2010
Posts: 825
    
    5

Please post SSCCE.

It is not enough to declare variables in constructor in order to use them throughout your class. You need to declare them as class fields (outside the constructor), otherwise they just act as local variables for the constructor (or any other block of code).

Edit: Playing around with threads without getting along with scope of variables is a tricky business by my oppinion.


The quieter you are, the more you are able to hear.
John Paterson
Ranch Hand

Joined: Mar 12, 2012
Posts: 116
Hi Kemal Sokolovic ,

Noted. Thanks.

regards
John
Rajdeep Biswas
Ranch Hand

Joined: Mar 26, 2012
Posts: 186

Hi John,

In java you got different scopes, class level, method level, etc...

So had you declared these variables in class level, you would not have got the error. But here, you have declared them in constructor, so compiler can see them inside that particular constructor only, and not in other scopes....so you are getting "can not find symbol" error....


Hope that helps.
Regards


The biggest gamble will be to ask a question whose answer you know in that it will challenge your theory | www.TechAspire.blogspot.in
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Cannot find symbol
 
Similar Threads
array problem
Java not installed right?
Constructor Question
Anyone know why I am getting this error (Regarding building an array based stack)
Cannot find symbol error