A project I have been tasked with requires that I create a banking simulation program. I have designed my program to be initiated within a "Controller" class that creates a HashMap, places default variables to be grabbed by my View class and sent to one of the 3 panels that exist within the view. My "Input" class, has a series of textfields that contain default values I intend on placing in there with references to the HashMap I mentioned earlier, allow them to be changed, and then sent to the HashMap and update the internal values within it to be sent across the program.

In the creation of my view class, I am running into a Null Pointer Exception that appears to originate when my input panel is created from within my view. My HashMap values are stored (I have tested their existence by placing output checks when they're added BEFORE the view is created), but when my Constructor for my controller class calls my view, my view seems to try to create my panels inside the view but blows up when trying to create the "input" panel and points to my first textfield saying that my method for acquiring the default values to place in my textfield is null. It's not though! Allow me to now present my code:

I apologize for it's extensive length, and if there is a more preferable method for me to post my questions in the future, I would be certainly happy to accommodate that. I've just been looking at this code for hours, and I can't seem to get any help from anyone on this... I don't just like throwing my code out there and being like, "Fix it", cause I certainly wouldn't want to insult profound programmers with my mundane tasks.

As far as i see, i think your panel has scope only inside the constructor and when it runs out of it, it throws NULL as there is no such object exists outside. Throw this statement as global to simInputPanel() and see.

getContentPane of which Container? There should be a container that will call this getContentPane().

March 30th, 2011, 09:25 AM

Newwisdom01

Re: Bank Simulation - Null Pointer Exception

I noticed a few of those observances you made and made adjustments without prevail. I moved the creation of panInput into the global variables as you had suggested and moved the creation of my Frame into the view as it should be (I don't know why I didn't in the first place) so the view code now looks like:

Which it would appropriately give this error for every instance of the TextFields for all of the variables... my path to my methods should be functioning correctly... communication to my view, which then communicates to my controller and returns the value to the panel in the form of an Integer from the HashMap and converts it into a String the TextField can use to appropriately set its defaults.

March 30th, 2011, 11:03 PM

Mr.777

Re: Bank Simulation - Null Pointer Exception

Code java:

view =new SimView(this);

Once you exit the form, why do you hope SimView to show "this". What "this" exists? Not exists. SO, you either need to hide instead of closing and then using this. Because as soon as you exit that form, there is null and with this statement, it throws null exception.

April 1st, 2011, 10:07 PM

Newwisdom01

Re: Bank Simulation - Null Pointer Exception

Well... to be honest, the problem was actually quite simple... it pains me to think I spent several hours on a 10 minute solution.
My panels had no means of communicating to my view. By sending to each panel's constructor an instance of my view with the line "panel = new SimInputPanel(this);" and for the other correlating panels, I could then immediately instantiate them within the constructor by making "this.view = view", and thus the communication is complete...