I just want ask why this question is off-topic:
-
9Read the explanation in the big yellow box underneath the question.– Cody Gray - on strike ModMay 2, 2019 at 6:22
-
3You added more code before it was closed but you deleted the stack trace. It probably would have been better to leave it in the question.– BSMPMay 2, 2019 at 6:23
-
2Also you can check this article from the help center.– πάντα ῥεῖMay 2, 2019 at 6:24
1 Answer
It was closed as off-topic for this reason:
"Questions seeking debugging help ("why isn't this code working?") must include the desired behavior, a specific problem or error and the shortest code necessary to reproduce it in the question itself. Questions without a clear problem statement are not useful to other readers. See: How to create a Minimal, Complete, and Verifiable example."
The word "Minimal" is key there. This is more minimal and I expect it will behave the same for the issue you are facing:
public class SerializeData {
private SerializeData() {}
public static DataConfig deserializeDataConfig(String filePath) {
DataConfig dataConfig = null;
try {
FileInputStream fileIn = new FileInputStream(filePath);
ObjectInputStream in = new ObjectInputStream(fileIn);
dataConfig = (DataConfig) in.readObject();
in.close();
fileIn.close();
} catch (IOException i) {
i.printStackTrace();
} finally {
return dataConfig;
}
}
}
DataConfig
class:
public class DataConfig implements Serializable {
private int year;
private int activeMonth;
public DataConfig(int year, int activeMonth) {
this.year = year;
this.activeMonth = activeMonth;
}
}
Main
here:
public class Main extends Application {
public static String PATH_CONFIG = "config.data";
public static DataConfig DATA_CONFIG;
public static void main(String[] args) {
try {
DATA_CONFIG = SerializeData.deserializeDataConfig(PATH_CONFIG);
}
catch (FileNotFoundException ex) { // this line causes troubles
ex.printStackTrace();
}
finally {
}
}
}
Please keep in mind I'm not a Java developer. I can't remember when I last touched that language so I might still have bugs here. For obvious reasons I didn't compile or test this MCVE. The onus is on you.
On top of that I think it is a duplicate as well as a quick search on the exception message reveals this. You might want to include links to such questions and explain why the answers didn't help you in your context. That will enable both the experts and future visitors to value your question and give a tailored answer.