KnowledgeHub
Questions
Tags
Users
Search
Alex Rivera
|
Logout
Edit Question
Title
Body
I'm running into the strangest error in this program, which is confirmed when debugging it. I have the following code (boiled down to highlight the problem, of course): BHFrame.java public class BHFrame { private boolean uSS; private StateSaver stateSaver; public BHFrame(boolean useInternalStateSaver) { //Init code uSS = useInternalStateSaver; //More init code System.out.println(uSS); if (uSS) {System.out.println("Entered 1"); stateSaver = new StateSaver(title, false); stateSaver.addSaveable(getThis()); } //More init code System.out.println(uSS); if (uSS) {System.out.println("Entered 2"); try { stateSaver.loadState(); stateSaver.putState(getThis()); } catch (IOException ex) { alertUserOfException(ex); } } } } GUI.java public class GUI extends BHFrame { public GUI(boolean useInternalStateSaver) { super(useInternalStateSaver); } } Main.java public class Main { public static void main(String[] args) { GUI gui = new GUI(false); } } Output false false Entered 2 Exception in thread "main" java.lang.NullPointerException at bht.tools.comps.BHFrame.<init>(BHFrame.java:26) at bhms.GUI.<init>(GUI.java:5) at bhms.Main.main(Main.java:5) The class BHFrame is extended and run from a child class that calls this constructor, but that really shouldn't affect this behavior. The problem is that, when false is passed to the constructor as useInternalStateSaver , the first if (uSS) is skipped, but the second is entered. Upon debugging, I found that uSS is false throughout runtime, including on the line of the second if statement, here
Tags (comma-separated)
Save Edits
Cancel