• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Changing color for button in arrary

 
B. Bent
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi to everybody. New to java and have a problem.
I construct an array of buttons and now I want to change background color of button when I click,
but I got null pointer exception. Can somebody help me with that.


Thanks
 
W Pearce
Ranch Hand
Posts: 32
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I think it's because you're re-decarling your instance variable array for your buttons in your constructor. Try changing
to
 
B. Bent
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It works.
And I search through internet couple days, and couldn't find solutions.

THANKS MAN !
 
Matthew Cox
Greenhorn
Posts: 29
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
B. Bent wrote:It works.
And I search through internet couple days, and couldn't find solutions.

THANKS MAN !


Yay!

Now, you should be wanting to understand WHY that fixed it.

Read up on "Scope of Variables"

This topic should help you understand why such a small change from


to



fixed your problem.
 
B. Bent
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Need to take second look on that obviously. I was confused because this was array.
Still learning basic things...
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic