2

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: https://i.stack.imgur.com/pOEWf.png

enter image description here

Hovercraft Full Of Eels
  • 283,665
  • 25
  • 256
  • 373
Kore
  • 436
  • 2
  • 14
  • 6
    For better help sooner, post a [MCVE] or [Short, Self Contained, Correct Example](http://www.sscce.org/). – Andrew Thompson Jul 26 '15 at 16:47
  • 1
    I can't reproduce this problem. Have you tried reinstalling Java, or turning your PC off and on again? – Pshemo Jul 26 '15 at 16:47
  • 6
    Post a **complete** minimal program reproducing the problem. – JB Nizet Jul 26 '15 at 16:48
  • 1
    BTW - `frame.setPreferredSize(screenSize);` should probably be `frame.setExtendedState(JFrame.MAXIMIZED_BOTH); // will account for the task bar!` – Andrew Thompson Jul 26 '15 at 16:49
  • @AndrewThompson I have posted it in the edit portion – Kore Jul 26 '15 at 17:07
  • @Pshemo I did both of those before asking the question – Kore Jul 26 '15 at 17:08
  • I am at a loss here. Question close vote retracted, and question up-voted for the minimal example program post. What happens when you try to run it from the command line? Also, you don't have your own class named `JFrame` within the same package do you? – Hovercraft Full Of Eels Jul 26 '15 at 17:12
  • *"Here is the minimum code required to reproduce the problem"* Two uncompilable code snippets do not make one MCVE! An MCVE needs the constructor and `main(String[])` in the same code block/class, and to include imports.. *"here is your proof"* `` don't post images of text. Copy/paste the **text.** Also note that the GUI should be created on the EDT. – Andrew Thompson Jul 26 '15 at 17:16
  • @HovercraftFullOfEels I don't have a JFrame class in it, and in my imports I am using the javax.swing.JFrame, so I cant see why it isnt working :( – Kore Jul 26 '15 at 17:17
  • @user3555001: nor can I, sorry. Again, have you tried to run the class code from the command line? If you do, take care that you don't ignore the package declaration as it is part of the full namespace of the program. – Hovercraft Full Of Eels Jul 26 '15 at 17:19
  • @AndrewThompson what I meant when I said here is the proof was that in my console section at the bottom it shows the Pre text, showing that the program ran, but it doesnt show to Post text that was called after a new JFrame() – Kore Jul 26 '15 at 17:20
  • @HovercraftFullOfEels I just tried that and it didnt work, thank you for the help, but Im not sure what to do now – Kore Jul 26 '15 at 17:21
  • could this possibly be a problem with a windows 7 setting? – Kore Jul 26 '15 at 17:44
  • 2
    It definitely seems like some sort of problem with your environment. When I run the code in your screenshot I see `Pre` and `Post` in the output. Do you have another computer you could try it on? Have you tried building and running your code with `javac` and `java` instead of in your IDE? – dimo414 Jul 26 '15 at 19:12

1 Answers1

0

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.

Community
  • 1
  • 1
Little Santi
  • 8,563
  • 2
  • 18
  • 46