简体   繁体   中英

When I call new JFrame() nothing happens

Here's my code:

Main component = new Main();
JFrame frame = new JFrame();
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setPreferredSize(screenSize);
frame.getContentPane().add(component);
frame.pack();
frame.setResizable(false);
frame.setVisible(true);
component.start();

When I run this nothing happened, so I put system.outs on every line, and I concluded that it stopped at the line:

JFrame frame= new JFrame();

I am really confused at what is happening, because I have run this exact same set of code many other times, but it has only started to cause me trouble recently.

Also to note, I do not receive any error messages when running this program, it will just run and get stuck at that line, then five seconds later just close the program.

I don't think this is a problem with my code since I have used this exact sequence of code many times before.

I have ran this program with java 7 and 8, so maybe it is a computer issue, so if you have any ideas please tell me!

[EDIT]

Here is the minimum code required to reproduce the problem

    public static void main(String args[]){
        JFrame frame = new JFrame();        
    }

here is your proof: http://i.stack.imgur.com/pOEWf.png

在此处输入图片说明

Do you say the program exits at line new JFrame without a visible stack trace? I recommend you apply two methods of tracing:

  1. Enclose your code within a try - catch (Throwable) block (just for debugging purposes, of corse) and print out the stacktrace of the Throwable object.

  2. More advanced: If you cannot get any Throwable in the previous manner, maybe a System.exit is being executed at some deep point of the code. If so, I recommend you program the SecurityManager to prevent it (see Preventing System.exit() from API ), and, within your code, print out the current stack trace, to know at least where does this strange System.exit come from.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM