Bob Matthews
,
Rancher
May 08, 2017 19:05:23
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
May 08, 2017 19:14:41
fcs_all, not fcs all. You miss _
Bob Matthews
,
Rancher
May 08, 2017 19:22:05
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
staff
May 08, 2017 19:26:59
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
,
Rancher
May 08, 2017 20:22:30
yes - the code is in the same block
continuous code
Bob M
Paul Clapham
,
Marshal
staff
May 08, 2017 23:11:27
Can you show us the whole method which contains that code?
Bob Matthews
,
Rancher
May 08, 2017 23:31:52
Paul Clapham
,
Marshal
staff
May 09, 2017 00:10:11
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
,
Rancher
May 09, 2017 00:20:18
OK...........
Could you guide me on how to correct my mistake?
John Joe
,
Ranch Hand
May 09, 2017 01:46:02
Declare FilteredClassifier fcs_all as global and remove all the FilteredClassifier in void might help.
Bob Matthews
,
Rancher
May 09, 2017 02:09:44
this rewrite fixes any problem with the variable fcs_all but I now have a problem with inputFile
John Joe
,
Ranch Hand
May 09, 2017 02:15:32
You are not follow my answer....
Change to Next, declare File as global variable.
Bob Matthews
,
Rancher
May 09, 2017 02:24:54
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
,
Rancher
May 09, 2017 03:27:04
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
,
Rancher
May 09, 2017 03:39:18
Thank you Dave....................
Error message: The local variable input may not have been initialized
Bob Matthews
,
Rancher
May 09, 2017 03:48:11
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
staff
May 09, 2017 04:17:08
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
Put the moon back where you found it! We need it for tides and poetry and stuff. Like this tiny ad:
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com