Win a copy of Re-engineering Legacy Software this week in the Refactoring forum
or Docker in Action in the Cloud/Virtualization forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Exception in thread "AWT-EventQueue-0"

 
Jackie Davis
Greenhorn
Posts: 23
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Exception in thread "AWT-EventQueue-0" java.lang.NullPointerException

This is driving me batty! I am guessing there is some fundamental flaw. I just can't figure out whats wrong.



Note** All the code isn't included.

The error is pointing to ScrollbarListener.adjustmentValueChanged. All I am trying to do is get the value of the Scrollbar and display it as a label. Everytime the Scrollbar is moved I would like to update the label.

Please help

Thanks

[ March 07, 2006: Message edited by: Jackie Davis ]
[ March 07, 2006: Message edited by: Jackie Davis ]
 
Keith Lynn
Ranch Hand
Posts: 2409
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Are you sure you initialize sbDeform? Since the NullPointerException occurs on that line, you probably have not initialized it.
[ March 07, 2006: Message edited by: Keith Lynn ]
 
Ernest Friedman-Hill
author and iconoclast
Marshal
Pie
Posts: 24208
35
Chrome Eclipse IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
And indeed, that's the case. You add(sbDeform), but you actually ininitialize a different, local variable named sbSmile, and add a listener to it -- but that ScrollBar is never added to the GUI anywhere.
 
Jackie Davis
Greenhorn
Posts: 23
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi, thanks for your replies.

I have fixed them silly errors and have edited my post accordingly.

Still having the same problem

 
Liz Hundy
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello,

I am a beginner myself so I may be talking rubbish.

But I had a similar problem and I fixed it by adding items to their containing panels before I added their listeners.

---Liz
 
Ernest Friedman-Hill
author and iconoclast
Marshal
Pie
Posts: 24208
35
Chrome Eclipse IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator


This is a tiny bit better, as now there's an actual ScrollBar being added to the panel. But you're still using a local variable instead of that member; even though the names are now the same, they're still two separate variables. When the event handler tries to access the (still uninitialized) member, you get the NPE. The first line above should look like

sbDeform= new Scrollbar(Scrollbar.HORIZONTAL, 0, 1, 0, 10);

Do you understand the problem now? It's actually quite important that you do -- this is a mistake that everybody makes once. Once you understand it, you won't make the same mistake again. When you specify the type for a variable in an assignment statement, like your version up there, you're declaring a new variable, distinct from any other previously existing ones. When you leave off that type, then you're referring to a variable that is declared elsewhere -- in this case, the member.
 
Jackie Davis
Greenhorn
Posts: 23
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks Ernest. That was very helpful.

I understand the concept now
 
Jackie Davis
Greenhorn
Posts: 23
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi there, another concept Im struggling with



I have methods defined in a Mesh class. I want to use these methods as the scrollbar is adjusted - (i.e. within the ScrollbarListener class - geo.someMethod() ) However geo is inialised in the MeshTesterGLSpace class. How can I use this object (geo) in the ScrollbarListener class?
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic