• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

JFileChooser is throwing NullPointerException

Lara Lance
Posts: 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi there,

I have a swing application that is using JFileChooser. When I click the Open menu item from File menu it should show the File dialog box where user can select the file.
This application is running in my machine but encounters problem in another machine. File dialog box is not showing and stack trace shows that NullPointerException is thrown by JFileChooser
My machine is a 64 bit Windows 7 while the other machine is Windows 7 32 bit. Both machine are using java 1.6
To verify if its because of the 32-bit, I tried in another Windows 7 32-bit and the same application is working.

I came across this article https://bugs.openjdk.java.net/browse/JDK-4711700 which identified it as bug but already fix in 1.4.2_04. Though I am using 1.6, just to make sure I also tried the suggested work around
I put System.setProperty("swing.disableFileChooserSpeedFix", "true"); in my code but still not working
I also tried to add java -Dswing.disableFileChooserSpeedFix=true to the batch file that is launching the application and still not working

Any other suggestions or idea on this? Thanks

Code Sample

Below is the stack trace

ERROR actions.menu.File_Open - Error occured while opening an existing timetable. null
caused by null java.lang.NullPointerException
at javax.swing.ImageIcon.<init><ImageIcon.java:215>
at javax.swing.ImageIcon.<init><ImageIcon.java:201>
at sun.swing.WindowPlaceBar.<init><WindowPlaceBar.java:94>
at com.sun.java.swing.plaf.windows.WindowFileChooserUI.updateUseShellFolder<WindowsFileChooserUI.java:542>
at com.sun.java.swing.plaf.windows.WindowFileChooserUI.installComponents<WindowsFileChooserUI.java:542>
at com.sun.java.swing.plaf.windows.WindowFileChooserUI.installComponents<WindowsFileChooserUI.java:219>
at java.swing.plaf.basic.basicFileChooserUI.installUI<BasicFileChooserUI.java:145>
at com.sun.java.swing.plaf.windows.WindowFileChooserUI.installUI<WindowsFileChooserUI.java:152>
at javax.swing.JComponent.setUI<JComponent.java:681>
at javax.swing.JFileChooser.updateUI<JFileChooser.java:1774>
at javax.swing.JFileChooser.setup<JFileChooser.java:371>
at javax.swing.JFileChooser.<init><JFileChooser.java:344>
at javax.swing.JFileChooser.<init><JFileChooser.java:297>
at actions.menu.File_Open.loadMDBFile<File_Open.java:221>

Joanne Neal
Posts: 3742
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Are you sure that is the code you are running ?
The stack trace shows you calling the loadMDBFile method in the File_Open class, but your code is showing a class called FileChooserTester
Campbell Ritchie
Posts: 50666
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Writing return null; is asking for trouble.
You have a method with a boolean return (why are you writing Boolean?) so users will expect it to tell them whether it opened the file or not. Users will expect to get true or false and to be able to use that value straight off without having to check for nulls.

Of course, as Joanne says, the method you are actually using may be different.

And welcome to the Ranch
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic