android应用程序在开始之前崩溃

时间:2013-03-19 22:36:20

标签: java android cordova

这是一个非常简单的应用程序,它适用于我添加

<script src="cordova-2.5.0.js" type="text/javascript"></script>

到我的index.html它在启动之前崩溃(在模拟器和实际设备中)这里是错误

03-19 21:24:28.633: E/AndroidRuntime(1467): FATAL EXCEPTION: main
03-19 21:24:28.633: E/AndroidRuntime(1467): java.lang.RuntimeException: Error receiving broadcast Intent { act=android.net.conn.CONNECTIVITY_CHANGE flg=0x10000010 (has extras) } in org.apache.cordova.NetworkManager$1@b49b2b50
03-19 21:24:28.633: E/AndroidRuntime(1467):     at android.app.LoadedApk$ReceiverDispatcher$Args.run(LoadedApk.java:737)
03-19 21:24:28.633: E/AndroidRuntime(1467):     at android.os.Handler.handleCallback(Handler.java:605)
03-19 21:24:28.633: E/AndroidRuntime(1467):     at android.os.Handler.dispatchMessage(Handler.java:92)
03-19 21:24:28.633: E/AndroidRuntime(1467):     at android.os.Looper.loop(Looper.java:137)
03-19 21:24:28.633: E/AndroidRuntime(1467):     at android.app.ActivityThread.main(ActivityThread.java:4424)
03-19 21:24:28.633: E/AndroidRuntime(1467):     at java.lang.reflect.Method.invokeNative(Native Method)
03-19 21:24:28.633: E/AndroidRuntime(1467):     at java.lang.reflect.Method.invoke(Method.java:511)
03-19 21:24:28.633: E/AndroidRuntime(1467):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:784)
03-19 21:24:28.633: E/AndroidRuntime(1467):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:551)
03-19 21:24:28.633: E/AndroidRuntime(1467):     at dalvik.system.NativeStart.main(Native Method)
03-19 21:24:28.633: E/AndroidRuntime(1467): Caused by: java.lang.SecurityException: ConnectivityService: Neither user 10042 nor current process has android.permission.ACCESS_NETWORK_STATE.
03-19 21:24:28.633: E/AndroidRuntime(1467):     at android.os.Parcel.readException(Parcel.java:1327)
03-19 21:24:28.633: E/AndroidRuntime(1467):     at android.os.Parcel.readException(Parcel.java:1281)
03-19 21:24:28.633: E/AndroidRuntime(1467):     at android.net.IConnectivityManager$Stub$Proxy.getActiveNetworkInfo(IConnectivityManager.java:597)
03-19 21:24:28.633: E/AndroidRuntime(1467):     at android.net.ConnectivityManager.getActiveNetworkInfo(ConnectivityManager.java:365)
03-19 21:24:28.633: E/AndroidRuntime(1467):     at org.apache.cordova.NetworkManager$1.onReceive(NetworkManager.java:107)
03-19 21:24:28.633: E/AndroidRuntime(1467):     at android.app.LoadedApk$ReceiverDispatcher$Args.run(LoadedApk.java:728)
03-19 21:24:28.633: E/AndroidRuntime(1467):     ... 9 more
03-19 21:24:28.672: E/dalvikvm(1467): VM aborting
03-19 21:24:28.672: A/libc(1467): Fatal signal 11 (SIGSEGV) at 0xdeadd00d (code=1)

1 个答案:

答案 0 :(得分:8)

添加:

<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>

到你的AndroidManifest.xml。

实际上在您的异常消息中说明了:

Caused by: java.lang.SecurityException: ConnectivityService: 
Neither user 10042 nor current process has android.permission.ACCESS_NETWORK_STATE.