So this is my code:
import javax.swing.*;
import java.awt.*;
public class ShapeTest extends JFrame{
public ShapeTest(){
setSize(600,600);
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
setLocationRelativeTo(null);
setVisible(true);
}
public static void main(String a[]){
new ShapeTest();
}
public void paint(Graphics g){
Rectangle[][] v = new Rectangle[200][200];
v[1][1].x=0;
v[1][1].y=0;
v[1][1].width=50;
v[1][1].height=50;
int y1=50;
for(int i=1; i<=7; i++){
int cont=50;
for(int j=1; j<=7; j++){
v[i][j].x+=cont;
v[i][j].y=y1;
cont+=70;
}
y1+=70;
}
for(int i=1; i<=7; i++){
for(int j=1; j<=7; j++){
g.drawRect(v[i][j].x, v[i][j].y, v[i][j].width, v[i][j].height);
g.setColor(Color.yellow);
g.fillRect(v[i][j].x, v[i][j].y, v[i][j].width, v[i][j].height);
}
}
}
}
and this is the sub-class:
public class Rectangle{
public int x;
public int y;
public int width;
public int height;
}
When I run the code, no rectangles are displayed, but i get a bunch of errors inside a text box:
Exception in thread "AWT-EventQueue-0" java.lang.NullPointerException
at ShapeTest.paint(ShapeTest.java:18)
this is the only error that is in red and I have no idea why it appears. I tried the other day running the code without arrays and it worked so I believe that might be the problem.