NullPointerException
仔细检查你的代码中的每个变量
看看有没有没有实例化就引用的成员变量

解决方案 »

  1.   

    public File myanotherTree(LinkedList myList,int time)
            {
             System.out.println("come into my another tree here ");
             myDir=new File(path);
             Stack myStack = new Stack();
                String str = new String();
            
             myStack.push(myDir);
             boolean bool;
            
             while(!myStack.empty())
             {
             tempdir=(File)myStack.pop();
             if(tempdir.isDirectory())
             {
             contents=tempdir.listFiles();
             str=String.valueOf(contents.length);
             for(int i=0; i< contents.length; i++)
             {
             myStack.push(contents[i]);
             }         bool=mylist(myList,str);
             if(!bool){
             k=0;
             bool = true;
             return tempdir;}
             }
             else 
             {
             bool = changedfile(tempdir,time);
             if(!bool){ bool= true; k=0; return tempdir;}
             }
             }
             k=0;
             System.out.println("------------------ Have done ---------------");
             return myDir;
            }
            
            public boolean  mylist(LinkedList myList,String str)
            {
             if(k==myList.size())
             {
             myList.add(str); k+=1;
                 return true;
             }
             else if(!str.equals(myList.get(k))){
                 myList.set(k,str);
             k+=1;
             return false;
             }
             else {
                  k+=1;
                  return true;
             }
            }
            
            public boolean changedfile(File tempdir,int time)
            {
             long j=tempdir.lastModified();
             long p=System.currentTimeMillis();
             if((p-j)<3*time)
             return false;
             else return true;
            
            }
         
     
    我用一个list把contents的length存放在里面,一旦文件夹中文件数目有改变就返回,同样,如果有文件被修改的话,也会由changedfile返回。谢谢帮偶看看是什么问题?
      

  2.   

    c盘下有个叫 system valume的目录(更准确地说是你的系统盘下)这个目录.listFiles();的时候会得到null.
      

  3.   

    哦,原来如此,那么怎么样才能解决这个问题呢?
    用什么可以代替.listFile()吗?
    谢谢~~~~~ ^^
      

  4.   

    File[] list = dir.listFile();
    if( null == list)
    {
        break;
    }我也没有更好的办法。