• Post Reply Bookmark Topic Watch Topic
  • New Topic

variable cannot be resolved  RSS feed

 
Bob Matthews
Ranch Hand
Posts: 136
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello

I am having trouble with the variable fcs_all
which java says cannot be resolved...............



Any suggestions appreciated

Bob M
 
John Joe
Ranch Hand
Posts: 436
3
Android Eclipse IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
fcs_all, not fcs all. You miss _
 
Bob Matthews
Ranch Hand
Posts: 136
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Not sure what you are talking about...........

By the way, the code is part of a weka data mining program

Bob M
 
Henry Wong
author
Sheriff
Posts: 23295
125
C++ Chrome Eclipse IDE Firefox Browser Java jQuery Linux VI Editor Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Question. Is that one code snippet? Or two?

Showing us a code snippet that declares the variable, and a snippet that uses it, is not enough. Are they in the same method? Are they in the same block? The compiler is complaining that the variable is not resolvable for a reason -- and the issue could be due to scope and/or access permissions.

Henry
 
Bob Matthews
Ranch Hand
Posts: 136
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
yes - the code is in the same block

continuous code

Bob M
 
Paul Clapham
Sheriff
Posts: 22829
43
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Can you show us the whole method which contains that code?
 
Bob Matthews
Ranch Hand
Posts: 136
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

 
Paul Clapham
Sheriff
Posts: 22829
43
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ah, I see... careful elision of code hides the fact that fcs_all is declared seven times in seven different blocks and is then used in code outside of those blocks. Naturally that fails.
 
Bob Matthews
Ranch Hand
Posts: 136
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
OK...........

Could you guide me on how to correct my mistake?
 
John Joe
Ranch Hand
Posts: 436
3
Android Eclipse IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Declare FilteredClassifier fcs_all as global and remove all the FilteredClassifier in void might help.
 
Bob Matthews
Ranch Hand
Posts: 136
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator


this rewrite fixes any problem with the variable fcs_all but I now have a problem with inputFile
 
John Joe
Ranch Hand
Posts: 436
3
Android Eclipse IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You are not follow my answer....
Change to   Next, declare File as global variable.
 
Bob Matthews
Ranch Hand
Posts: 136
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I'm sorry but I do not follow your instructions..............

I get the part about deleting "File"

but I am unsure of how to declare File as a global variable

I read that the word static is involved?
 
Dave Tolls
Ranch Foreman
Posts: 3061
37
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Beyond the fact that that is a lot of code in a single method, I think John is suggesting declaring 'input' before all the if statements, rather than actually 'global'.
eg


That will ensure that 'input' is in scope.

However, I would prefer to Map<Integer, String> or even Map<Integer, File>, and populate that Map outside of all this code, so you could then simply:

(that one assumes a Map<Integer, File>)

Gets all those if statements out of there.

Ultimately, though, you ought to break that code up.
Even if it's just into methods, rather than classes.
 
Bob Matthews
Ranch Hand
Posts: 136
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thank you Dave....................


Error message: The local variable input may not have been initialized

 
Bob Matthews
Ranch Hand
Posts: 136
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

File input = null;
if ( j == 0) {
input = new File("C:/Users/Stan/Documents/Weka/USDJPY_S/Model1/KStar1.model"); }
if ( j == 1) {
input = new File("C:/Users/Stan/Documents/Weka/USDJPY_S/Model2/J48.model"); }
if ( j == 2) {
input = new File("C:/Users/Stan/Documents/Weka/USDJPY_S/Model3/JRip.model"); }
if ( j == 3) {
input = new File("C:/Users/Stan/Documents/Weka/USDJPY_S/Model4/NaiveBayes.model"); }
if ( j == 4) {
input = new File("C:/Users/Stan/Documents/Weka/USDJPY_S/Model5/LMT.model"); }
if ( j == 5) {
input = new File("C:/Users/Stan/Documents/Weka/USDJPY_S/Model6/KStar2.model"); }
if ( j == 6) {
input = new File("C:/Users/Stan/Documents/Weka/USDJPY_S/Model7/LibSVM.model"); }

ObjectInputStream ois = new ObjectInputStream(
                           new FileInputStream(input));
FilteredClassifier fcs_all = (FilteredClassifier) ois.readObject();
ois.close();
[/code]


All good and clean now.......................
Thank you so much for your assistance

However, I would prefer to Map<Integer, String> or even Map<Integer, File>, and populate that Map outside of all this code, so you could then simply:


(that one assumes a Map<Integer, File>)

Gets all those if statements out of there.

Ultimately, though, you ought to break that code up.
Even if it's just into methods, rather than classes.

I need to read about this procedure - it is out of my knowledge at the moment
 
Henry Wong
author
Sheriff
Posts: 23295
125
C++ Chrome Eclipse IDE Firefox Browser Java jQuery Linux VI Editor Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Bob Matthews wrote:yes - the code is in the same block

continuous code


Well, from following the rest of the discussion, it is clearly *not* in the same block. And certainly *not* "continuous code"...

Anyway, glad you worked it out.

Henry
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!