I've created a small swing application which has 2 tabs.
the contents of each tab is created in a seperate class returning a JPanel.
The 2nd tab is where the user can edit, delete, or create new files.
When either a new file is created or an existing one is deleted an array is updated containing
the names of remaining files.
The 1st Tab is where the user would be able to read files and compare files with other files.
So on the 1st Tab there is a JComboBox which contains the list of files.
In my frame class is where I implement the JTabbedPane for the two tabs.
Here is where I have the changeListener located.
Here's the code where I'm having the issue:
Seems every time I try this I get a NullPointerException where indicated below in the code.
I also tried to putting the body of code I have within the ChangeListener above into its own
method of the 1st Tab class and call it from the ChangeListener of the frame class and also
get a NullPointerException in the same place.
Let me know if if you have any ideas on this, I've scoured oracles site and countless others with no luck
and have worked on solving this on my own for two days now, feeling quite frustrated at this point.
I think you will get no error if you used your existing MainPanel. (I think you mentioned as my Panel to MainPanel)
posted 7 years ago
Thanks for checking this out.
There are four classes involved in this.
My entire application has 13 classes.
The code for the ChangeListener is located in the class I have my main method in.
The class MainPanel class is a seperate class that holds several methods which build the Panels for the first tab.
and The AddEditFormatter class is a seperate class that holds several methods which build the Panels for the second tab.
I hope that helps in understanding the local issue I presented.
I've verified that the JComboBox (select_cmb) located in the MainPanel class is not null.
But I still get a NullPointerException when I try to access it.
I've done this before without issue back in Java SE version 1.4, can't seem to figure out what's changed in verion 6
and what's replaced this usage. I've read over the documentation several times of what I could find, just haven't
found anything other than old documentation saying this method of doing this won't be supported after version 1.4.2.
There's got to be another way that exists to do the same thing.
Any help would be appreciated.
posted 7 years ago
I got this one figured out. :-)
I changed my code to the following:
Then from my MainPanel class I created the updateComboboxSelections() method as follows:
I actually tried this same approach in my first attempt and failed.
It seems the only thing different was my making mp a class varible.