Search code examples
javalinuxheadless

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);
    }
}

Solution

  • 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