NPE在Environment.getExternalStorageState()? [英] NPE on Environment.getExternalStorageState()?
问题描述
找不到为什么我收到空指针异常的原因。我可以给一个明确的检查,看看是否getStorageState为空,但是,这并不说明为什么我收到此错误。 错误是:
显示java.lang.NullPointerException
在android.os.Environment.getStorageState(Environment.java:719)
在android.os.Environment.getExternalStorageState(Environment.java:694)
在com.ciqual.android.insight.sessionService.RemoveFiles(SessionService.java:664)
com.vyshas.android.sessionService.onEndSession(SessionService.java:460)
在:(线路的错误指的是这样的:)(豆形软糖中的4.3和奇巧看到)
如果(Environment.getExternalStorageState()。等于(Environment.MEDIA_MOUNTED)){
//
}
Environment.MEDIA_MOUNTED.equals(Environment.getExternalStorageState)wouldnt导致NPE而Environment.getExternalStorageState()。等于(Environment.MEDIA_MOUNTED)不会导致NPE和崩溃应用程序。
我仍然不知道为什么getExternalStorageState为空eventhough我有设定权限,但解决方案ATLEAST不会崩溃的应用程序。
Cannot find the reason why I am getting "Null pointer exception" . I could give an explicit check to see if "getStorageState is null" but that doesnt explain why I am getting this error. The error is :
java.lang.NullPointerException
at android.os.Environment.getStorageState(Environment.java:719)
at android.os.Environment.getExternalStorageState(Environment.java:694)
at com.ciqual.android.insight.sessionService.RemoveFiles(SessionService.java:664)
com.vyshas.android.sessionService.onEndSession(SessionService.java:460)
at : (the line that error points to is this :)(seen in jellybean 4.3 and kitkat)
if(Environment.getExternalStorageState().equals(Environment.MEDIA_MOUNTED)) {
//
}
Environment.MEDIA_MOUNTED.equals(Environment.getExternalStorageState) wouldnt cause a NPE while Environment.getExternalStorageState().equals(Environment.MEDIA_MOUNTED) does cause NPE and crashes the application.
I still dont know why getExternalStorageState is null eventhough I have permissions set but the solutions atleast wouldn't crash the application.
这篇关于NPE在Environment.getExternalStorageState()?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!