krnbatta / android-file-dialog

Automatically exported from code.google.com/p/android-file-dialog
0 stars 0 forks source link

File dialog crashes with NullPointerException #2

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
File dialog crashes with NullPointerException if dirPath does not exists.

03-10 18:15:17.289: ERROR/AndroidRuntime(1438): Caused by: 
java.lang.NullPointerException
03-10 18:15:17.289: ERROR/AndroidRuntime(1438):     at 
com.loudsoft.loudbook.FileDialog.getDirImpl(FileDialog.java:177)
03-10 18:15:17.289: ERROR/AndroidRuntime(1438):     at 
com.loudsoft.loudbook.FileDialog.getDir(FileDialog.java:137)
03-10 18:15:17.289: ERROR/AndroidRuntime(1438):     at 
com.loudsoft.loudbook.FileDialog.onCreate(FileDialog.java:125)
03-10 18:15:17.289: ERROR/AndroidRuntime(1438):     at 
android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047)
03-10 18:15:17.289: ERROR/AndroidRuntime(1438):     at 
android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1611)

I offer this solution:

    private void getDirImpl(String dirPath) {

        File f = new File(dirPath);
                // Use root directory if dirPath does not exists
        if(!f.exists())
        {
            Toast.makeText(context, "There is no such directory " + dirPath, duration).show();
            dirPath = root;
            f = new File(root);
        }

        myPath.setText(getText(R.string.location) + ": " + dirPath);
        currentPath = dirPath;

        item = new ArrayList<String>();
        path = new ArrayList<String>();
        mList = new ArrayList<HashMap<String, Object>>();

        File[] files = f.listFiles();

Такие дела =)

Original issue reported on code.google.com by ppv....@gmail.com on 10 Mar 2011 at 3:31

GoogleCodeExporter commented 9 years ago
Надо посмотреть :)

Original comment by alexande...@gmail.com on 24 Mar 2011 at 9:42

GoogleCodeExporter commented 9 years ago
ppv....@gmail.com, thanks a lot for your report, I've fixed the bug :)

Original comment by alexande...@gmail.com on 18 Aug 2011 at 7:44