0

Boiled down code for starting the thread for my window:

public static LiDrThread lidrThread;
public void onKeyInput(InputEvent.KeyInputEvent event){
   if( lidrThread== null || !lidrThread.isAlive())
   {
      lidrThread= new LiDrThread();
      lidrThread.start();
   }
}

Overriden run method in my LiDrThread class, it extends Thread

private LightDrafterWindow window;
@Override
public void run() {
    try {
        LogHelper.info("Initializing window");
        window = new LightDrafterWindow();
        LogHelper.info("Setting window Visible");
        window.setVisible(true); // altered since original post
    } catch (Exception e) {
        LogHelper.warn("Window failed to open");
        e.printStackTrace();
    }
}

This is the boiled down code for my constructor, my window extends JFrame:

public JPanel contentPane;
public LightDrafterWindow() {
    LogHelper.info("Accessing PlayerName");
    LogHelper.info("Accessing Player Capabilities");

    LogHelper.info("Setting up basics of Window");
    //setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); // line 48
    setBounds(100, 100, 450, 300);
    contentPane = new JPanel();
    setContentPane(contentPane);
    contentPane.setLayout(null);

    //PlayerInfo section -----------------------------------------------------------------------------------------------
    LogHelper.info("Initializing player info panel");
    contentPane.setVisible(true);
}

there is more after the last LogHelper but this is what shows up in my console:

[18:12:46] [Thread-15/INFO] [lidr]: Initializing window
[18:12:46] [Thread-15/INFO] [lidr]: Accessing PlayerName
[18:12:46] [Thread-15/INFO] [lidr]: Accessing Player Capabilities
[18:12:46] [Thread-15/INFO] [lidr]: Setting up basics of Window
[18:12:46] [Thread-15/WARN] [lidr]: Window failed to open
[18:51:14] [Thread-15/INFO] [STDERR]: [main.java.lidr.thread.LiDrThread:run:23]: java.lang.ArrayIndexOutOfBoundsException: 5
[18:51:14] [Thread-15/INFO] [STDERR]: [main.java.lidr.thread.LiDrThread:run:23]:    at net.minecraftforge.fml.relauncher.FMLSecurityManager.checkPermission(FMLSecurityManager.java:21)
[18:51:14] [Thread-15/INFO] [STDERR]: [main.java.lidr.thread.LiDrThread:run:23]:    at java.lang.SecurityManager.checkExit(Unknown Source)
[18:51:14] [Thread-15/INFO] [STDERR]: [main.java.lidr.thread.LiDrThread:run:23]:    at javax.swing.JFrame.setDefaultCloseOperation(Unknown Source)
[18:51:14] [Thread-15/INFO] [STDERR]: [main.java.lidr.thread.LiDrThread:run:23]:    at main.java.lidr.thread.LightDrafterWindow.<init>(LightDrafterWindow.java:48)
[18:51:14] [Thread-15/INFO] [STDERR]: [main.java.lidr.thread.LiDrThread:run:23]:    at main.java.lidr.thread.LiDrThread.run(LiDrThread.java:18)

At this point I am not sure what could be going wrong. It seems to be failing on the generated code and I just don't know enough about Gui's to see anything wrong with this.

If you want to see more of the code of I have this project on github

EDIT------------ After commenting out the line that is causing this error, nothing else is causing errors, however the jframe is still not displaying. updated code to reflect changes.

UberAffe
  • 332
  • 2
  • 3
  • 15
  • try to take output of e.printStackTrace() line and edit the question. It will print the exact problem. – Yusuf K. Mar 15 '16 at 23:42
  • 3
    Your title is awful. Please change it to a very brief summary of your problem. Then, stop breaking coding conventions, because "I'll fix when I get it working" might be the reason you can't find the bug. Then, edit the question to remove your code and add an [MCVE] for the code -- that is, the minimum possible code to get the same error from the same thing. – Nic Mar 15 '16 at 23:43
  • Part of why I don't know how to troubleshoot further is that I don't know how to break this down into MCVE. It could take a year to fully understand the environment that forge provides for Minecraft Modding. – UberAffe Mar 16 '16 at 00:05

2 Answers2

1

The problem came from inside of Forge code. There is code inside that prevents any classes from calling system exit.

The solution was to use DISPOSE_ON_CLOSE.

UberAffe
  • 332
  • 2
  • 3
  • 15
0

you have to add your panel to a JFrame, then set it visible. without Frame you will not see a GUI. add those line in the end.

yourframe.add(contentPane);
yourframe.setvisible(true)
yourframe.pack();
The Appsolit
  • 89
  • 10
  • I think we can assume that `setContentPane(contentPane);` is adding the pane to the frame, also, it would not example the exception – MadProgrammer Mar 16 '16 at 00:29
  • JPanel is a component so it's suitable to use add(Component) not addcontentpane. – The Appsolit Mar 16 '16 at 00:32
  • Since we don't have a class declaration for `LightDrafterWindow` and they are using `setContentPane` and the code compiles it's a safe assumption that `LightDrafterWindow` is a window based class, so `setContentPane` will apply the `JPanel` to the frame as the "base" component – MadProgrammer Mar 16 '16 at 00:48
  • LightDrafterWindow extends JFrame – UberAffe Mar 16 '16 at 00:51
  • From the stack it's clear that the problem come from your thread, so you tried to use lidrThread without initialization, i propose that you initialize this variable before checking the rest of code. @UberAffe – The Appsolit Mar 16 '16 at 02:07
  • @MadProgrammer the jFrame contain already a contentpane why we have to set a content pane, we can use directly add(Component), see this thread http://stackoverflow.com/a/2433123/2228261 that explain somme difference between add(component) and setcontentpane – The Appsolit Mar 16 '16 at 02:09
  • I understand the differences, the main reason for using setContentPane is to supplement your own logic (such as a background image pane) which means you don't need to modify any code which might have been adding other components to the frame. My point is, what the op was doing exactly what you were suggesting (just through a different API/approach) and suggestion would not solve there problem and is just adding unnecessary noise – MadProgrammer Mar 16 '16 at 02:16