• Post Reply Bookmark Topic Watch Topic
  • New Topic

NPE when setting text in jLabel  RSS feed

 
miguel lisboa
Ranch Hand
Posts: 1281
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
i set this jLabel's text dinamically; now, i added an itemListener to a combo and want to change label's text according to selection, but i keep getting this infuriating null point exception.
how can i turn it around?

TiA
 
Michael Dunn
Ranch Hand
Posts: 4632
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
symptom of duplicate declarations
1) class field
2) local variable (in constructor, or initComponents() etc)

(2) is what is added to the frame, and you see it on your screen, (1) is the
one referenced by the listener, and is null.

in the absence of any code, this is just a guess.
 
miguel lisboa
Ranch Hand
Posts: 1281
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
it looks like you'r right, but i cant find my way out
i'm using eclipse, so i create my label like:

and now i wrote, inside my listener:

and indeed prints true!!!
so i guess i have an initialization order problem: how can i delay listener so that it awakes after panel is created?

thanks again
[ April 09, 2007: Message edited by: miguel lisboa ]
 
miguel lisboa
Ranch Hand
Posts: 1281
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
i found my way out: in my gui i've an initialize method that called my combo before (so it looks like) panel creation, so i forced this happening before

ty
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!