This week's giveaway is in the Spring forum.
We're giving away four copies of REST with Spring (video course) and have Eugen Paraschiv on-line!
See this thread for details.
The moose likes Beginning Java and the fly likes JList null pointer exception Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of REST with Spring (video course) this week in the Spring forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "JList null pointer exception" Watch "JList null pointer exception" New topic

JList null pointer exception

Scott A Burch
Ranch Hand

Joined: Jan 04, 2011
Posts: 57
I am trying to get a button to open a file directory, retrieve some file names and add them as elements to a JLIst. The code opens the filechooser flawlessly, but the minute I click OK in the save dialog, I get a null pointer exception.

The problem comes with the button listener. I get null pointer exception at:

Please help me sort this out. Thanks!
Scott A Burch
Ranch Hand

Joined: Jan 04, 2011
Posts: 57
Figured it out. I had created a local variable listModel and was hiding the list field.

I changed the line


and it works. And the delete button works now too. Thanks!
I agree. Here's the link:
subject: JList null pointer exception
It's not a secret anymore!