Note that there are some explanatory texts on larger screens.

plurals
  1. POJFileChooser fails
    primarykey
    data
    text
    <p>In my code at a certain point i have this code</p> <pre><code>void selectRoot() { JFileChooser ch = new JFileChooser(); ch.showOpenDialog((JFrame)this); } </code></pre> <p>This throws that Exception:</p> <pre><code>Exception in thread "AWT-EventQueue-0" java.lang.NullPointerException at java.io.Win32FileSystem.normalize(Win32FileSystem.java:164) at java.io.Win32FileSystem.getUserPath(Win32FileSystem.java:296) at java.io.Win32FileSystem.resolve(Win32FileSystem.java:312) at java.io.File.getAbsolutePath(File.java:501) at sun.awt.shell.Win32ShellFolder2.&lt;init&gt;(Win32ShellFolder2.java:291) at sun.awt.shell.Win32ShellFolderManager2.createShellFolderFromRelativePIDL(Win32ShellFolderManager2.java:66) at sun.awt.shell.Win32ShellFolderManager2.createShellFolder(Win32ShellFolderManager2.java:56) at sun.awt.shell.Win32ShellFolderManager2.getRecent(Win32ShellFolderManager2.java:114) at sun.awt.shell.Win32ShellFolderManager2.get(Win32ShellFolderManager2.java:251) at sun.awt.shell.ShellFolder.get(ShellFolder.java:227) at sun.swing.WindowsPlacesBar.&lt;init&gt;(WindowsPlacesBar.java:64) at com.sun.java.swing.plaf.windows.WindowsFileChooserUI.updateUseShellFolder(WindowsFileChooserUI.java:505) at com.sun.java.swing.plaf.windows.WindowsFileChooserUI.installComponents(WindowsFileChooserUI.java:196) at javax.swing.plaf.basic.BasicFileChooserUI.installUI(BasicFileChooserUI.java:136) at com.sun.java.swing.plaf.windows.WindowsFileChooserUI.installUI(WindowsFileChooserUI.java:129) at javax.swing.JComponent.setUI(JComponent.java:673) at javax.swing.JFileChooser.updateUI(JFileChooser.java:1763) at javax.swing.JFileChooser.setup(JFileChooser.java:360) at javax.swing.JFileChooser.&lt;init&gt;(JFileChooser.java:333) at javax.swing.JFileChooser.&lt;init&gt;(JFileChooser.java:286) at my.pack.Main.selectRoot(Main.java:184) </code></pre> <p>Looking in the source of java.io.Win32FileSystem.normalize() it seems the (current) path is null:</p> <pre><code> public String normalize(String path) { int n = path.length(); // Line: 164 char slash = this.slash; char altSlash = this.altSlash; </code></pre> <p>If i run selectRoot() from another point in the program it runs fine ...</p> <p><strong>Update</strong></p> <p>Guys that is really a good one for the great book of programing pitfalls !</p> <p>In my original code there is a JTextField that holds the actual path and get initialize that way:</p> <pre><code>root = new JTextField(); root.setToolTipText("Root folder"); root.setText(System.clearProperty("user.dir")); </code></pre> <p>System.clearProperty() clears the system property (to null) <strong>and</strong> returns the old value (arrrghhhhhhh). clearProperty() probably slipped in from auto-completion.</p> <p>Thank you all. Will give some up votes to you ...</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload