I am trying to slowly fill a power-up bar which is a single big white rectangle slowly being overlapped by a yellow rectangle. I initially created a white and yellow rectangle with the x of the yellow one constantly changing. I am subtracting my game score to add 1 to the rectangle each time my score goes up by 1. Unfortunately I am getting an NullPointerException error when I run the program. This is occurring at the yellowRectangle.setSize line.
public void powerUp(Graphics2D win) {
win.setColor(Color.white);
Rectangle whiteRectangle = new Rectangle(685, 500, 100, 25);
Rectangle yellowRectangle = new Rectangle(685, 500, myX, 25);
win.fill(whiteRectangle);
}
public void draw(Graphics2D win) {
if (gameState == 1) {
scoreBoard(win, score);
if(myX <= 100 && myRocket.score > 1) {
myX += myRocket.score - (myRocket.score - 1);
yellowRectangle.setSize(myX, 25);
win.setColor(Color.yellow);
win.fill(yellowRectangle);
}
powerUp(win);
}
}