I’m trying to read the data from a file that I’ve saved. This code is a part for reading the data “Value”. But the compiler says there is an error at the last part ‘return Value;’. It says ‘Value cannot be resolved as a variable’. What should I do?
public static double[] getValue(){
FileInputStream fis = null;
ObjectInputStream ois = null;
List<Double> newList = new ArrayList<Double>();
try {
fis = new FileInputStream("user_data.txt");
ois = new ObjectInputStream(fis);
double[] Value = (double[]) ois.readObject();
} catch (Exception ex) {
try {
fis.close();
ois.close();
} catch (IOException e) {
e.printStackTrace();
}
}
return Value;
}
Your problem is that you declare
Valueinsidetry, so it’s not visible outside. Try this instead: