Here's an example stack trace:
https://github.com/carlb710/myRepo/blob/main/exception
My program has a GUI created using the IntelliJ Swift GUI designer. The only GUI related code I have actually written has been inside the autogenerated constructor, inside autogenerated listeners for buttons and check boxes on my GUI. Everything else has been in the .form file created by the GUI manager. The stack trace for the null pointer exception looks a bit different each time it comes up, but it's always an issue in the same thread. As far as I can tell, the issue appears to be related to an issue in the Swing code and not necessarily my own. The error does not come up every time the program is launched, and it always occurs when the JFrame is either first set visible in my Main class, or when the JFrame is refreshed. Here is the code I use to instantiate my GUI and set it visible (this is the first code run in the main class, so it's the very first thing that happens when the program is launched):
public static void main(String[] args){
App programWindow = new App();
JFrame frame = new JFrame("Java QA Checker");
frame.setContentPane(programWindow.landing);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.pack();
frame.setVisible(true); //stack trace sometimes points to this as the start of an exception
Font font = new Font("Helvetica", Font.PLAIN, 16);
//programWindow.textArea1.setFont(font);
//sets look and feel based on OS
try{
UIManager.setLookAndFeel(new UIManager().getSystemLookAndFeelClassName());
SwingUtilities.updateComponentTreeUI(frame); // To refresh your GUI
}catch(Exception e){
try {
UIManager.setLookAndFeel(new MetalLookAndFeel());
} catch (UnsupportedLookAndFeelException ex) {
ex.printStackTrace();
}
SwingUtilities.updateComponentTreeUI(frame); // To refresh your GUI
}
//loop I added after the fact to make the JFrame refresh until exceptions occur since they do not consistently start with the start of the program
boolean loop = false;
while (!loop){
SwingUtilities.updateComponentTreeUI(frame);
}
beyond that, all the code that affects the GUI I have commented out and has been ruled out of the equation. I also commented out the autogenerated constructor for the GUI that contains the rest of the code related to listeners and stuff, the same exceptions occur whether or not that code is compiled, so I can reasonably assume that code is not directly causing the issue. I was wondering if maybe the issue was related to the constructor since it did not explicitly make statements like
this.sampleTextArea = sampleTextArea;
I also wanted to note that I have tried changing the look and feel code to be explicitly one look instead of interpreting based on OS, and the same exceptions occur they just trace to the code related to that specific look and feel. Same types of error though, mouse pointer is null, this.caret is null, etc. etc.