本帖最后由 hackerain 于 2011-09-11 14:08:18 编辑

解决方案 »

  1.   

    if(file.toString().toLowerCase().endsWith(".png")||
    如果file是null的话就报空指针异常了have a try
    public boolean accept(File file)
    {
      if (file == null) reurn false;
      return (file.toString().toLowerCase().endsWith(".png")|| file.isDirectory());
    }
      

  2.   

    file在什么情况下就是null了呢?为什么有的时候会报null的错,有的时候不报呢?
      

  3.   


    而且按你说的改了一下,问题依然存在,还是时有时无,报的错是这样的:
    Exception in thread "Basic L&F File Loading Thread" java.lang.NullPointerException
    是某个线程出了错?
      

  4.   

    JFileChooser jfc=new JFileChooser(new File(".")); //have a try
      

  5.   

    哦,原来这是jdk的一个bug啊!http://bugs.sun.com/view_bug.do;jsessionid=ba24c23e8dc7944129c6b5c658b9?bug_id=6756220
      

  6.   

    试试看用SwingUtilities.invokeLater能不能改善
    for example
    SwingUtilities.invokeLater(new Runnable(){
        public void run() {
            ...
       }
    });