简体   繁体   English

当我调用新的JFrame()时,什么都没有发生

[英]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: 当我运行此命令时,什么也没发生,所以我将system.outs放在每行上,然后得出结论,它在行上停止了:

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! 我已经使用Java 7和8运行了该程序,所以也许是计算机问题,所以如果您有任何想法请告诉我!

[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 这是您的证明: http : //i.stack.imgur.com/pOEWf.png

在此处输入图片说明

Do you say the program exits at line new JFrame without a visible stack trace? 您是否说程序在new JFrame退出而没有可见的堆栈跟踪? 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. 将您的代码包含在try - catch (Throwable)块中(仅出于Corse的调试目的),并打印出Throwable对象的stacktrace。

  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. 更高级:如果您无法以以前的方式获取任何Throwable,则可能是在代码的某个深处执行了System.exit 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. 如果是这样,我建议您对SecurityManager进行编程以防止它发生(请参阅从API防止System.exit() ),并在您的代码中打印出当前的堆栈跟踪信息,以至少了解这个奇怪的System.exit来自何处。 。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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