Forums Register Login

variable cannot be resolved

+Pie Number of slices to send: Send
Hello

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



Any suggestions appreciated

Bob M
+Pie Number of slices to send: Send
fcs_all, not fcs all. You miss _
+Pie Number of slices to send: Send
Not sure what you are talking about...........

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

Bob M
+Pie Number of slices to send: Send

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
+Pie Number of slices to send: Send
yes - the code is in the same block

continuous code

Bob M
+Pie Number of slices to send: Send
Can you show us the whole method which contains that code?
+Pie Number of slices to send: Send

+Pie Number of slices to send: Send
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.
+Pie Number of slices to send: Send
OK...........

Could you guide me on how to correct my mistake?
+Pie Number of slices to send: Send
Declare FilteredClassifier fcs_all as global and remove all the FilteredClassifier in void might help.
+Pie Number of slices to send: Send


this rewrite fixes any problem with the variable fcs_all but I now have a problem with inputFile
+Pie Number of slices to send: Send
You are not follow my answer....
Change to  Next, declare File as global variable.
+Pie Number of slices to send: Send
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?
+Pie Number of slices to send: Send
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.
+Pie Number of slices to send: Send
Thank you Dave....................


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

+Pie Number of slices to send: Send

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
+Pie Number of slices to send: Send
 

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


reply
reply
This thread has been viewed 569 times.
Similar Threads
Serialization - overriding readObject()
doubt in reading object file
Serialization query
How to know the number of items in your Seralization/Deserialization stream?
Serialization
More...

All times above are in ranch (not your local) time.
The current ranch time is
Mar 29, 2024 08:09:30.