This is my first time encountering GUI's and as I've been learning and searching, I've been trying to do some exercises and i've encountered this error. Would someone please be kind and explain why is this happening? Thank you very much. The error is "Cannot invoke "java.awt.Graphics.setColor(java.awt.Color)" because "g" is null"
import java.awt.Graphics;
import java.awt.Color;
import java.awt.Canvas;
import javax.swing.JFrame;
public class Circle extends Canvas {
public Circle() {
JFrame frame = new JFrame("Circle Exercise");
Canvas paper = new Canvas();
frame.setSize(500, 500);
frame.setVisible(true);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.add(paper);
}
@Override
public void paint(Graphics g) {
g.setColor(Color.RED);
g.drawOval(100, 100, 200, 200);
}
public static void main(String[] args) {
Circle drawing = new Circle();
drawing.paint(null);
}
}