Everytime I try to run the program I keep getting the "NullPointerException" error message. Along with this other stuff:
Exception in thread "Animation Thread" java.lang.NullPointerException
at Project_2_.setup(Project_2_.java:40)
at processing.core.PApplet.handleDraw(PApplet.java:1402)
at processing.core.PApplet.run(PApplet.java:1327)
at java.lang.Thread.run(Thread.java:613)
Here's my code.
Code:String[] rows = {
"grass",
"water",
"water",
"water",
"water",
"grass",
"road",
"road",
"road",
"road",
"grass"};
Lane[] allLanes;
int grassColor = color(18, 173, 5);
int waterColor = color(18, 23, 227);
int roadColor = color(17, 17, 18);
void setup () {
size (700,500);
smooth ();
allLanes = new Lane[rows.length];
for(int i = 0; i < allLanes.length; i++) allLanes[i].drawLane();
}
void draw () {
for(int i = 0; i < allLanes.length; i++) allLanes[i].drawLane();
}
class Lane {
color laneColor = color(0);
int rowHeight = 0;
int yPos = 0;
Lane(String type, int yRow){
if(type.equals("grass")) this.laneColor = grassColor;
if(type.equals("water")) this.laneColor = waterColor;
if(type.equals("road")) this.laneColor = roadColor;
this.rowHeight = height / rows.length;
this.yPos = this.rowHeight * yRow;
}
int drawLane() {
fill (this.laneColor);
rect (0,this.yPos, width, this.rowHeight);
return yPos;
}
}
Any help would be appreciated.