Milanesa-chan
Milanesa-chan

Reputation: 111

Java crashes when creating a JFrame

I am baffled at this issue. I just wanted to create a JFrame for testing, this is the only class:

import javax.swing.*;

public class TextPaneTest extends JFrame {

    public TextPaneTest(){
        setTitle("Test");
        setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
        setLocationRelativeTo(null);
        setSize(200, 200);
        setVisible(true);
    }

    public static void main(String[] args){
        new TextPaneTest();
    }
}

I am using IntelliJ IDEA 2019.2.4 as my IDE.

The result is a small white JFrame opens up for 2 seconds and closes. You can't move or resize the window and the cursor remains in "wait" mode when you hover the frame.

This is my project structure:

project structure

And this is my run configuration:

run configuration

There is no error message or exception. All the console shows is:

Process finished with exit code -1073740771 (0xC000041D)

I've already done a clean reinstall of both the JRE and JDK

This is my current java -version:

java version "1.8.0_231"
Java(TM) SE Runtime Environment (build 1.8.0_231-b11)

My OS is Windows 10 Home Single Language 1903

I don't know what else to add. I've been using Java for the past 5 years as a hobbyist and I've never came across an issue so fundamental as this.

Update

None has worked so far. Exactly the same behaviour.

Update 2

Fixed it by switching the 64 bit JRE for the 32 one. Is this a bug with the 64 one or could there be an underlying problem?

Upvotes: 0

Views: 546

Answers (1)

Elliott Frisch
Elliott Frisch

Reputation: 201447

I cannot reproduce the issue on my macintosh, but I notice you are doing everything on the main thread. You shouldn't do that. Make sure all events happen on the Event Dispatch Thread. For example,

public static void main(String[] args) {
    SwingUtilities.invokeLater(new Runnable() {
        public void run() {
            new TextPaneTest();
        }
    });
}

Upvotes: 2

Related Questions