I'm trying to build a game and I have an error that comes up. I'm relatively new to coding so any help is appreciated.
I try to run the following in Java to set up a frame using the JFrame library, but end up getting an error. Thoughts on a solution?
package com.key.gameproject;
import javax.swing.JFrame;
public class MainClass {
public static void main(String args[]) {
System.out.println("Test");
JFrame frame = new JFrame();
frame.setSize(640, 480);
frame.setResizable(false);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setVisible(true);
}
}
Error:
Test
Exception in thread "main" java.lang.NullPointerException
at java.awt.Window.init(Window.java:497)
at java.awt.Window.<init>(Window.java:537)
at java.awt.Frame.<init>(Frame.java:420)
at java.awt.Frame.<init>(Frame.java:385)
at javax.swing.JFrame.<init>(JFrame.java:189)
at com.key.gameproject.MainClass.main(MainClass.java:9)
Update: I reinstalled Eclipse, Java and still running into the same issue. Tried in a different IDE and also ran through terminal (javac, java) and still nothing works
Update 3/11 - I'm trying to run this on Mac high sierra which results in the above error. However, on Windows it seems okay. javax.swing.JFrame (JFrame.java:189) looks exactly the same on both machines. Again, I have already reinstalled multiple times and appreciate the help so far (@camickr). The issue is still not resolved and I can't find a similar issue on Stack.