This week's book giveaway is in the Android forum.
We're giving away four copies of Head First Android and have Dawn & David Griffiths on-line!
See this thread for details.
The moose likes Beginning Java 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 Head First Android this week in the Android forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Exception in thread "main" java.lang.NullPointerException" Watch "Exception in thread "main" java.lang.NullPointerException" New topic

Exception in thread "main" java.lang.NullPointerException

Andrew Sepulveda

Joined: Oct 02, 2011
Posts: 10
the user interface class

the main class

I am not sure why I am getting this...

I am running on eclipse and it does not show in the code itself that it is an error, only in the console.
Anybody realize why this is happening?
Ralph Cook
Ranch Hand

Joined: May 29, 2005
Posts: 479
One of the great things about Java is that the error messages usually give you a good idea of what's going on; just read them carefully.

In your case it says "NullPointerException", and "", meaning line 22 in that class.

line 22 contains "item.addItemListener..."; you should be wondering if item has been instantiated.

And you can look back and see that, although you declared item to be a JComboBox, you never instantiated a JComboBox to put in it.

Andrew Sepulveda

Joined: Oct 02, 2011
Posts: 10
thank you. the program now works functionally.
It is sorta covered in the JavaRanch Style Guide.
subject: Exception in thread "main" java.lang.NullPointerException
It's not a secret anymore!