A little view of swing exception

As a beginner of swing: Although I know the exceptions such as null pointer, array out of bounds, etc., but I don't understand the exception at the beginning of the following. And it is unstable, and sometimes it does not report an exception.

Exception in thread "AWT-EventQueue-0" java.lang.NullPointerException

Exception in thread "AWT-EventQueue-0"java.lang.ArrayIndexOutOfBoundsException

Looking at "AWT-EventQueue-0" here, it is probably that an exception was reported in the event. It's all guesswork, experts are welcome to answer.

I can't control that much, go to the code to see

JFrame frame=new JFrame("打卡客户端系统");
  frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
  frame.setSize(WIDTH,HEIGHT);
  frame.setVisible(true);
  frame.setLocationRelativeTo(null);

 

Then add a label and create a button in the label. etc

Here frame.setVisible(true); does not mean to display the frame? If the component is not fully loaded or initialized, the frame is displayed. Move
this sentence to the end of the program to see it. Sure enough, all the above Exceptions are gone.

The location of the code creates program instability.

The above conclusion is correct, but the reason and the idea of ​​solving the problem are all blind cats and dead mice. Experts are welcome to give the correct answer.

 

 

Guess you like

Origin http://10.200.1.11:23101/article/api/json?id=326569810&siteId=291194637