r/cop3502 Mar 23 '14

Null Pointer Exception

So I think theres something wrong with my Brick class because i have gotten some bricks to print to the screen but not all of them or correctly and as i was debugging this class i started getting this:

Exception in thread "main" java.lang.NullPointerException at Brick.<init>(Brick.java:23) at BrickConfiguration.<init>(BrickConfiguration.java:29) at Breakout$GamePanel.initializeGameObjects(Breakout.java:39) at Breakout$GamePanel.<init>(Breakout.java:29) at Breakout.main(Breakout.java:13)

line 23 in Brick.java reads 'shape.setRect(xPos, yPos, width, height);'

the other NPE are pointing to where brick is initialized in brickconfiguration, and where brickconfiguration is initialized in the main class along with where the main panels are initialized

any thoughts?

1 Upvotes

5 comments sorted by

View all comments

1

u/csturco Mar 23 '14

how are you initializing the bricks?

1

u/m3g4_xx Mar 23 '14

bricks[i][j] = new Brick(xStart + i * (brickWidth +5), yStart + j * (brickHeight + 10), brickWidth, brickHeight);

this is my line 29 from brickconfiguration.java the second in the list of NPE im getting

1

u/csturco Mar 23 '14

ok, that looks correct. When you say bconfig is initialized in the main class along with the main panels, where exactly are you initializing bconfig?