Forums Register Login

Error on seting images to labels: NullPointException

+Pie Number of slices to send: Send
Hi,

Please have a look at the following code


Class mainWindow




Class Preview



The problem is, when I run the application and click on the "Preview" button, it open the window without the output I need and gives this error

Exception in thread "Thread-3" java.lang.NullPointerException
at preview$ThreadClass.run(preview.java:70)


I know what this error means, but I can't find anything which I haven't declared! .... Please help meeee.....>
+Pie Number of slices to send: Send
Please help.........
+Pie Number of slices to send: Send
PatienceIsAVirtue. Kicking after 3 hours is not done.

Line 70 is icon = new ImageIcon(selectedFiles[i].getAbsolutePath());. If that's throwing an NPE it means that selectedFiles or selectedFiles[i] is null. It isn't the former, so selectedFiles[i] must be null. That's caused by line 29 - you discard the existing value of your selectedFiles parameter and assign a new array with only null values. Remove that line completely and your code will work - somewhat.

You have a similar error on line 69 of mainWindow: p = new preview(miliSeconds, selectedFiles, selectedFiles.length);. Now, what is the value of selectedFiles before you've selected any files?

Another error: line 57 will ignore the last element of the array.

And finally, the one that you're probably not aware of - you should never ever ever access the user interface in any way from a thread that is not the Event Dispatcher Thread. Read this for more information. The best solution is to use a javax.swing.Timer.


Oh, and next time, UseTheForumNotEmail (or private messages).
+Pie Number of slices to send: Send
 

Rob Spoor wrote:Oh, and next time, UseTheForumNotEmail (or private messages).


+1
+Pie Number of slices to send: Send
 

Rob Spoor wrote:PatienceIsAVirtue. Kicking after 3 hours is not done.

Line 70 is icon = new ImageIcon(selectedFiles[i].getAbsolutePath());. If that's throwing an NPE it means that selectedFiles or selectedFiles[i] is null. It isn't the former, so selectedFiles[i] must be null. That's caused by line 29 - you discard the existing value of your selectedFiles parameter and assign a new array with only null values. Remove that line completely and your code will work - somewhat.

You have a similar error on line 69 of mainWindow: p = new preview(miliSeconds, selectedFiles, selectedFiles.length);. Now, what is the value of selectedFiles before you've selected any files?

Another error: line 57 will ignore the last element of the array.

And finally, the one that you're probably not aware of - you should never ever ever access the user interface in any way from a thread that is not the Event Dispatcher Thread. Read this for more information. The best solution is to use a javax.swing.Timer.




Thanks a lot for your reply...That helped me a lot! I thought I will have to do a huge change, but it is not!! Thanks for the line 69 error too.. I ran several test drives, this is also one, but I can't understand why I missed that!!!
Thanks for the thread related issue too. I will have a deep look at it, and will come back to the "Threads" section with a question...




+Pie Number of slices to send: Send
 

Rob Spoor wrote:
Oh, and next time, UseTheForumNotEmail (or private messages).


Darryl Burke wrote:+1



Pardon me if I made any inconvenience...
Creativity is allowing yourself to make mistakes; art is knowing which ones to keep. Keep this tiny ad:
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com


reply
reply
This thread has been viewed 1117 times.
Similar Threads
Files.copy() command is not working
JPanels with different content should have the same size
Setting look and feel of a component
JFileChooser: Selecting multiple files error
Layout question
More...

All times above are in ranch (not your local) time.
The current ranch time is
Mar 29, 2024 08:51:26.