在这些特定条件下,我的应用将无法启动:
- 没有网络连接
- 在设备上启动
并给出 FileNotFoundException 因为我没有任何权限(请参阅下面的堆栈跟踪)。在其他情况下,这有效。我从 mysql 数据库中检索数据。在主要活动的 onCreate 方法中,我检查互联网连接。
我在清单中有这些权限:
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.WRITE_INTERNAL_STORAGE" />
我正在主要活动中检查互联网连接:
private boolean isNetworkAvailable() {
ConnectivityManager connectivityManager = (ConnectivityManager) getSystemService(Context.CONNECTIVITY_SERVICE);
NetworkInfo activeNetworkInfo = connectivityManager.getActiveNetworkInfo();
if(activeNetworkInfo.isAvailable()){
return true;
}
else {
return false;
}
错误信息:
11-07 14:15:16.176: E/AndroidRuntime(27318): Uncaught handler: thread main exiting due to uncaught exception
11-07 14:15:16.176: E/Monkey(27318): exception :java.io.FileNotFoundException: /dev/kmsg: open failed: EACCES (Permission denied)
11-07 14:15:16.200: E/AndroidRuntime(27318): exception :java.io.FileNotFoundException: /dev/kmsg: open failed: EACCES (Permission denied)
11-07 14:15:16.200: E/AndroidRuntime(27318): exception :java.io.FileNotFoundException: /dev/kmsg: open failed: EACCES (Permission denied)
11-07 14:15:16.200: E/AndroidRuntime(27318): FATAL EXCEPTION: main
11-07 14:15:16.200: E/AndroidRuntime(27318): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.phi.oudemarkt/com.phi.oudemarkt.MainActivity}: java.lang.NullPointerException