Skip to main content
GameDev.net gamedev.net
🔒 Locked

[java] Newbie is stuck! Help!

Started by Zook Sep 29, 2000 at 4:08 AM 3 replies 650+ views
Original Post
Zook
Zook
How can I make an array of Buttons, or any other objects? I have this line Button [][] b=new Button[size][size]; and at run-time I get the error NullPointerException when I try to access the member functions. What`s wrong?
ARCHIGAMER
ARCHIGAMER
you have not defined the objects that you created they all have no value (null) which is illegal in java.

I wish there was a button on my monitor to turn up the intellegince.
Theres a button called 'brightness' but it doesn't work
I wish there was a button on my monitor to turn up the intellegince. Theres a button called 'brightness' but it doesn't work
bobbin
bobbin

When you define an array you build the array object (not strictly true, but anyway) but don''t initialize the elements (the object inside the array). You need to construct the elements before you can reference them (ie b[x][y] = new button())..
Hodglim
Hodglim
This might help ...


Button [][] b = new Button[size][size];
for(int x = 0; x < size; x++)
for(int y = 0; y < size; y++)
b[x][y] = new Button();




Edited by - Hodglim on September 29, 2000 11:47:08 AM
- HodglimHomepage
Zook
Zook
Yeah, it works!!
Thanks for the help guys!

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.