• Post Reply Bookmark Topic Watch Topic
  • New Topic

Error on seting images to labels: NullPointException  RSS feed

 
Yohan Weerasinghe
Ranch Hand
Posts: 507
Java Netbeans IDE Oracle
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.....>
 
Yohan Weerasinghe
Ranch Hand
Posts: 507
Java Netbeans IDE Oracle
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Please help.........
 
Rob Spoor
Sheriff
Posts: 20903
81
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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).
 
Darryl Burke
Bartender
Posts: 5167
11
Java Netbeans IDE Opera
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Rob Spoor wrote:Oh, and next time, UseTheForumNotEmail (or private messages).

+1
 
Yohan Weerasinghe
Ranch Hand
Posts: 507
Java Netbeans IDE Oracle
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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...




 
Yohan Weerasinghe
Ranch Hand
Posts: 507
Java Netbeans IDE Oracle
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Rob Spoor wrote:
Oh, and next time, UseTheForumNotEmail (or private messages).

Darryl Burke wrote:+1


Pardon me if I made any inconvenience...
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!