Note that there are some explanatory texts on larger screens.

plurals
  1. POJFileChooser's anomaly with MyComputer in Windows
    text
    copied!<p>I created a file chooser using swing to select only images from a windows platform. I used a <code>FileFilter</code> to do that. The code of the <code>accept()</code> method overridden form the <code>FileFilter</code> class is: </p> <pre><code>public boolean accept(File f) { System.out.println("File is : " + f.getName() + " " + f); if(f.isDirectory()) return true; String ext = getExtension(f); // returns extensions of the files. if(ext.equals("jpg") || ext.equals("jpeg") || ext.equals("gif") || ext.equals("tif") || ext.equals("tiff")) return true; else { return false; } </code></pre> <p>It hangs when <code>MyComputer</code> is selected form the windows desktop. The following is the entry i get for MyComputer:</p> <p><code>File is ::{20D04FE0-3AEA-1069-A2D8-08002B30309D} Computer</code></p> <p>And the following is the error message I get:</p> <pre><code>File is ::{20D04FE0-3AEA-1069-A2D8-08002B30309D} Computer File is lenovo C:\Users\lenovo File is ::{F02C1A0D-BE21-4350-88B0-7367FC96EF3C} Network File is ::{031E4825-7B94-4DC3-B131-E946B44C8DD5} Libraries File is 4s.txt C:\Users\lenovo\Desktop\4s.txt File is cs.bat - Shortcut.lnk C:\Users\lenovo\Desktop\cs.bat - Shortcut.lnk File is kaushik.txt C:\Users\lenovo\Desktop\kaushik.txt File is rel.txt C:\Users\lenovo\Desktop\rel.txt File is SQL Developer.lnk C:\Users\lenovo\Desktop\SQL Developer.lnk File is Get Started With Oracle Database 11g Express Edition .lnk C:\Users\Public\Desktop\Get Started With Oracle Database 11g Express Edition .lnk </code></pre> <p>The following is displayed after double-clicking myComputer:</p> <pre><code>File is ::{416651E4-9C3C-11D9-8BDE-F66BAD1E3F3A} ::{20D04FE0-3AEA-1069-A2D8-08002B30309D}\::{416651E4-9C3C-11D9-8BDE-F66BAD1E3F3A} Exception in thread "Basic L&amp;F File Loading Thread" java.lang.NullPointerException at gui.ImageFilter.accept(ImageFilter.java:26) at javax.swing.JFileChooser.accept(JFileChooser.java:1576) at javax.swing.plaf.basic.BasicDirectoryModel$LoadFilesThread$1.call(BasicDirectoryModel.java:230) at javax.swing.plaf.basic.BasicDirectoryModel$LoadFilesThread$1.call(BasicDirectoryModel.java:216) at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:303) at java.util.concurrent.FutureTask.run(FutureTask.java:138) at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:886) at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:908) at sun.awt.shell.Win32ShellFolderManager2$ComInvoker$3.run(Win32ShellFolderManager2.java:458) at java.lang.Thread.run(Thread.java:619) </code></pre> <p>However when i add another <code>if</code> condition right after <code>ext</code> is initialized: </p> <pre><code>if (ext == null) return false; </code></pre> <p>It runs fine. My question is if <code>MyComputer</code> is a directory why it was bothered by the <code>null</code> test? Shouldn't it have returned <code>true</code> at the directory test? On the other hand, if it is not a directory (which makes it a file, right?), then how is it still returning <code>true</code> and getting opened by the file chooser? Or is their some other exceptional angle to it?</p> <p>Thanx in advance!</p>
 

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