This week's giveaway is in the Android forum.
We're giving away four copies of Android Security Essentials Live Lessons and have Godfrey Nolan on-line!
See this thread for details.
The moose likes Java in General and the fly likes Exception in thread Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Java » Java in General
Bookmark "Exception in thread "AWT-EventQueue-0"" Watch "Exception in thread "AWT-EventQueue-0"" New topic
Author

Exception in thread "AWT-EventQueue-0"

Jackie Davis
Greenhorn

Joined: Mar 04, 2006
Posts: 23
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

Joined: Feb 07, 2005
Posts: 2367
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

Joined: Jul 08, 2003
Posts: 24183
    
  34

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.


[Jess in Action][AskingGoodQuestions]
Jackie Davis
Greenhorn

Joined: Mar 04, 2006
Posts: 23
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

Joined: Feb 21, 2006
Posts: 11
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

Joined: Jul 08, 2003
Posts: 24183
    
  34



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

Joined: Mar 04, 2006
Posts: 23
Thanks Ernest. That was very helpful.

I understand the concept now
Jackie Davis
Greenhorn

Joined: Mar 04, 2006
Posts: 23
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?
 
Don't get me started about those stupid light bulbs.
 
subject: Exception in thread "AWT-EventQueue-0"
 
Similar Threads
Brain Fog
Vector help
Using object in different class
Parsing a text file to an arraylist
JOGL problem