为什么Environment.getExternalStorageState()在Android中出现NullPointException

时间:2015-09-16 08:32:18

标签: java android

我的代码

private static String getSDCardPath() {
    boolean sdCardExist = Environment.MEDIA_MOUNTED.equals(Environment.getExternalStorageState());
    if (sdCardExist) {
        return Environment.getExternalStorageDirectory().toString();
    }
    return null;
}

引起:

java.lang.NullPointerException
at android.os.Environment.getExternalStorageState(Environment.java:602)

0 个答案:

没有答案