Erro ao tentar tirar print da tela com java [RESOLVIDO]

Eu estou tentando fazer um programa que tire várias prints da tela mas está me dando erro.

Exception in thread "Thread-0" java.lang.NullPointerException
    at screenrecorder.Main.recorder(Main.java:77)
    at screenrecorder.Main.tick(Main.java:72)
    at screenrecorder.Main.run(Main.java:87)
    at java.base/java.lang.Thread.run(Thread.java:834)

O código é o seguinte:

package print;

import java.awt.Canvas;
import java.awt.Dimension;
import java.awt.Rectangle;
import java.awt.Robot;
import java.awt.Toolkit;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.image.BufferedImage;
import java.io.File;
import java.io.IOException;

import javax.imageio.ImageIO;
import javax.swing.JButton;
import javax.swing.JFrame;

   public class Main extends Canvas implements Runnable,ActionListener {

private int WIDTH = 160;
private int HEIGHT = 120;
private int SCALE = 2;
private boolean isRunning;
private Rectangle allScreen;
private int counter;

private JFrame frame;
private JButton btn;	

private Thread thread;
private Robot robot;

public Main() {
	this.setPreferredSize(new Dimension(WIDTH * SCALE, HEIGHT*SCALE));
	allScreen = new Rectangle(Toolkit.getDefaultToolkit().getScreenSize());
}

public void window() {
	frame = new JFrame();
	btn = new JButton("Print");
	
	btn.setBounds(120, 80, 80, 25);
	btn.setVisible(true);
	btn.addActionListener(this);
	frame.add(btn);
	
	frame.add(this);
	frame.setLocationRelativeTo(null);
	frame.setDefaultCloseOperation(frame.EXIT_ON_CLOSE);
	frame.setResizable(false);
	frame.pack();
	frame.setVisible(true);
}

public static void main(String[] args) {
	Main main = new Main();
	main.window();
	main.start();
}

public synchronized void start() {
	thread = new Thread(this);
	thread.start();
}

public synchronized void stop() {
	
}

public void tick() {
	if(isRunning) {
	  recorder();
	}
}

public void recorder() {
	BufferedImage print = robot.createScreenCapture(allScreen);
	try {
		ImageIO.write(print, "png", File.createTempFile("image", "png"));
	} catch (IOException e) {
		e.printStackTrace();
	}
}

public void run() {
	while(true) {
		tick();
		try {
			thread.sleep(1000/60);
		} catch (InterruptedException e) {
			e.printStackTrace();
		}
	}
}


public void actionPerformed(ActionEvent e) {
	isRunning = true;
	
}

}

O código está funcionando, só da erro quando eu coloco essa parte:

BufferedImage print = robot.createScreenCapture(allScreen);
    try {
	ImageIO.write(print, "png", File.createTempFile("image", "png"));
    } catch (IOException e) {
	e.printStackTrace();
}

Provavelmente você tenha esquecido de instanciar o objeto robot, não?

E quando instanciar o objeto robot e executar sua classe receberá, possivelmente, a seguinte mensagem, se estiver utilizando o Java Runtime da Oracle.
#
# A fatal error has been detected by the Java Runtime Environment:
#
# SIGSEGV (0xb) at pc=0x00007f88423ffaf1, pid=5122, tid=0x00007f8841bcd700
#
# JRE version: Java™ SE Runtime Environment (8.0_241-b07) (build 1.8.0_241-b07)
# Java VM: Java HotSpot™ 64-Bit Server VM (25.241-b07 mixed mode linux-amd64 compressed oops)
# Problematic frame:
# C [libawt_xawt.so+0x46af1] ReadRegionsInList.constprop.5+0x671
#
# Core dump written. Default location: /home/NetBeansProjects/JavaApplication1/src/core or core.5122
#
# An error report file with more information is saved as:
# /home/NetBeansProjects/JavaApplication1/src/hs_err_pid5122.log
#
# If you would like to submit a bug report, please visit:
# http://bugreport.java.com/bugreport/crash.jsp
# The crash happened outside the Java Virtual Machine in native code.
# See problematic frame for where to report the bug.
#