So basically i' m following a youtube series on making a 2d game and i 've placed some code in but i get this annoying error, HELP ME PLEASE:
package com.weebly.alfiemartin.Game;
import java.awt.*;
import javax.swing.*;
public class gMain extends Canvas implements Runnable{
private static final long serialVersionUID = 1L;
public static int width = 300;
public static int height = width / 16 * 9;
public static int scale = 3;
private Thread gameThread;
private boolean running = false;
private JFrame window = new JFrame();
public gMain(){
Dimension screenSize = new Dimension(width*scale, height * scale);
setPreferredSize(screenSize);
window = new JFrame();
}
public synchronized void start(){
running = true;
gameThread = new Thread(this, "Display");
gameThread.start();
}
public synchronized void stopThread(){
running = false;
try{
gameThread.join();
}catch(InterruptedException e){
e.printStackTrace();
}
}
public void run(){
while(running){
System.out.println("Hello My Name Is Alfie");
}
}
public static void main(String args[]){
gMain gMain = new gMain();
gMain.window.setResizable(false);
gMain.window.setTitle("First Game");
gMain.window.add(gMain);
gMain.window.pack();
gMain.window.setDefaultCloseOperation(JFrame.EXIT_ ON_CLOSE);
gMain.window.setLocation(null);
gMain.window.setVisible(true);
gMain.start();
}
}
Exception in thread "main" java.lang.NullPointerException
at java.awt.Component.setLocation(Unknown Source)
at java.awt.Window.setLocation(Unknown Source)
at com.weebly.alfiemartin.Game.gMain.main(gMain.java: 52)
Any help is appreciated, thank you!