遇到File.contains(文件)和File.add(文件)的麻烦

时间:2014-09-25 23:38:25

标签: android file

我尝试编写Android应用程序代码。

下面的代码应该将文件的父项添加到我的列表中,但前提是父项不在列表中。

files[]是目录中的文件数组

imageFolders的创建方式如下:

private List <File> imageFolders;
private String [] extensions;
File [] files = folder.listFiles();
extensions = new String [] {".png",".jpg",".jpeg"};

//important part: 

if(files[i].toString().contains(extensions[b]))
{
    System.out.println("Checkpoint 1");                     
    if(!imageFolders.contains((File)files[i].getParentFile()))
    {  
        System.out.println("Checkpoint 2");
        imageFolders.add((File)files[i].getParentFile());
    }
 }

然后日志给我这个,应用程序关闭:

09-26 08:33:55.580: I/System.out(1753): /system/lib/hw/camera.goldfish.jpeg.so //gives me the file[i]   
09-26 08:33:55.580: I/System.out(1753): Checkpoint 1    
09-26 08:33:55.590: D/AndroidRuntime(1753): Shutting down VM    
09-26 08:33:55.610: W/dalvikvm(1753): threadid=1: thread exiting with uncaught exception 
(group=0xb1a87ba8)    
09-26 08:33:55.650: E/AndroidRuntime(1753): FATAL EXCEPTION: main    
09-26 08:33:55.650: E/AndroidRuntime(1753): Process: de.FriedSloth.fastphotomanager, PID: 1753    
09-26 08:33:55.650: E/AndroidRuntime(1753): java.lang.RuntimeException: Unable to start activity 
ComponentInfo{de.FriedSloth.fastphotomanager/de.FriedSloth.fastphotomanager.Side2}: java.lang.NullPointerException    
09-26 08:33:55.650: E/AndroidRuntime(1753):     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2195)    
09-26 08:33:55.650: E/AndroidRuntime(1753):     at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2245)    
09-26 08:33:55.650: E/AndroidRuntime(1753):     at android.app.ActivityThread.access$800(ActivityThread.java:135)

09-26 08:33:55.650: E/AndroidRuntime(1753):     at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1196)   
09-26 08:33:55.650: E/AndroidRuntime(1753):     at android.os.Handler.dispatchMessage(Handler.java:102)
09-26 08:33:55.650: E/AndroidRuntime(1753):     at android.os.Looper.loop(Looper.java:136)   
09-26 08:33:55.650: E/AndroidRuntime(1753):     at android.app.ActivityThread.main(ActivityThread.java:5017)    
09-26 08:33:55.650: E/AndroidRuntime(1753):     at java.lang.reflect.Method.invokeNative(Native 
Method)
09-26 08:33:55.650: E/AndroidRuntime(1753):     at java.lang.reflect.Method.invoke(Method.java:515)   
09-26 08:33:55.650: E/AndroidRuntime(1753):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:779)   
09-26 08:33:55.650: E/AndroidRuntime(1753):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:595)    
09-26 08:33:55.650: E/AndroidRuntime(1753):     at dalvik.system.NativeStart.main(Native Method)    
09-26 08:33:55.650: E/AndroidRuntime(1753): Caused by: java.lang.NullPointerException   
09-26 08:33:55.650: E/AndroidRuntime(1753):     at de.FriedSloth.fastphotomanager.Side2.hSearchImages(Side2.java:61)   
09-26 08:33:55.650: E/AndroidRuntime(1753):     at de.FriedSloth.fastphotomanager.Side2.hSearchImages(Side2.java:52)   
09-26 08:33:55.650: E/AndroidRuntime(1753):     at de.FriedSloth.fastphotomanager.Side2.hSearchImages(Side2.java:52)    
09-26 08:33:55.650: E/AndroidRuntime(1753):     at de.FriedSloth.fastphotomanager.Side2.onCreate(Side2.java:32)    
09-26 08:33:55.650: E/AndroidRuntime(1753):     at android.app.Activity.performCreate(Activity.java:5231)

09-26 08:33:55.650: E/AndroidRuntime(1753):     at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1087) 
09-26 08:33:55.650: E/AndroidRuntime(1753):     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2159)    
09-26 08:33:55.650: E/AndroidRuntime(1753):     ... 11 more

0 个答案:

没有答案