aspose file tools*
The moose likes Beginning Java and the fly likes NullPointerException Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of The Java EE 7 Tutorial Volume 1 or Volume 2 this week in the Java EE forum
or jQuery UI in Action in the JavaScript forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "NullPointerException" Watch "NullPointerException" New topic
Author

NullPointerException

jwiscou chen
Greenhorn

Joined: Sep 13, 2006
Posts: 7
when I run follow code have a NullPointerException occured can anyBody help me

Thanks Advance
sven studde
Ranch Hand

Joined: Sep 26, 2006
Posts: 148
when I run follow code have a NullPointerException

Edit your post and add a comment to the line of code on which Java told you the exception occurred. Something like:

//**THE ERROR IS HERE***
[ November 06, 2006: Message edited by: sven studde ]
Henry Wong
author
Sheriff

Joined: Sep 28, 2004
Posts: 18743
    
  40

The stacktrace from a null pointer exception, provides the java filename, the line number within that file, along with the callstack.

If you are having problems deciphering it. Provide us with the trace, and we'll show you what to look at next.

Henry


Books: Java Threads, 3rd Edition, Jini in a Nutshell, and Java Gems (contributor)
Michael Dunn
Ranch Hand

Joined: Jun 09, 2003
Posts: 4632
if your npe is in valueChanged(), wrap the
label.setIcon(icon);
in a SwingUtilities.invokeLater(...

you will also have to change
ImageIcon icon ..
to
final ImageIcon icon ..
jwiscou chen
Greenhorn

Joined: Sep 13, 2006
Posts: 7
Thanks for your advice now I modify to follow can anyone help me

Michael Dunn
Ranch Hand

Joined: Jun 09, 2003
Posts: 4632
your problem is that you create the JList before creating the label.
when the JList is created, a valueChanged event is fired, and in this the label,
which is referenced, is still null.

couple of solutions
1) see earlier reply re SwingUtilities
2) create the label before creating the list

label = new JLabel(new ImageIcon(file[0].getPath()));//<----move to here
list = new JList(fileName);
jwiscou chen
Greenhorn

Joined: Sep 13, 2006
Posts: 7
now I know thank you
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: NullPointerException