简体   繁体   中英

I switched to Linux and now I get a java.awt.HeadlessException

I am making a 2D game engine using the core java library, and just switched to linux. Before my game engine would run fine, but now that I've switched to linux, when I try to run the code, it throws a java.awt.HeadlessException.

How can i fix this?

This is the class that throws the error. I'm not sure how much it's gonna help though. There's a lot more to it. I'm pretty sure the only important thing is that I use the awt library for keyevents.

package Platformer;

import java.awt.Dimension;

import javax.swing.JFrame;

public class Game {
    public static void main(String args[]){
        JFrame frame=new JFrame();
        GameComponent gp=new MainGame();
        frame.add(gp);
        frame.pack();
        frame.setSize(1920, 1080);
        frame.setLocationRelativeTo(null);
        frame.setVisible(true);
    }
}

The exception says that the JRE which is installed in that linux machine might not contain headless JRE.

Headless JRE are the package which provides dependencies used for the graphical components.

Check your Java installation, if in doubt, try reinstalling

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