我在设置部分停用移动数据时出现以下错误消息。有人可以帮忙吗?提前谢谢!
崩溃日志
06-04 13:14:45.569: E/PluginManager(23862): Uncaught exception from plugin
06-04 13:14:45.569: E/PluginManager(23862): java.lang.NullPointerException
06-04 13:14:45.569: E/PluginManager(23862): at org.apache.cordova.networkinformation.NetworkManager.getConnectionInfo(NetworkManager.java:201)
06-04 13:14:45.569: E/PluginManager(23862): at org.apache.cordova.networkinformation.NetworkManager.execute(NetworkManager.java:133)
06-04 13:14:45.569: E/PluginManager(23862): at org.apache.cordova.CordovaPlugin.execute(CordovaPlugin.java:65)
06-04 13:14:45.569: E/PluginManager(23862): at org.apache.cordova.PluginManager.execHelper(PluginManager.java:242)
06-04 13:14:45.569: E/PluginManager(23862): at org.apache.cordova.PluginManager.exec(PluginManager.java:227)
06-04 13:14:45.569: E/PluginManager(23862): at org.apache.cordova.ExposedJsApi.exec(ExposedJsApi.java:53)
06-04 13:14:45.569: E/PluginManager(23862): at org.apache.cordova.CordovaChromeClient.onJsPrompt(CordovaChromeClient.java:227)
06-04 13:14:45.569: E/PluginManager(23862): at android.webkit.CallbackProxy.handleMessage(CallbackProxy.java:738)
06-04 13:14:45.569: E/PluginManager(23862): at android.os.Handler.dispatchMessage(Handler.java:99)
06-04 13:14:45.569: E/PluginManager(23862): at android.os.Looper.loop(Looper.java:137)
06-04 13:14:45.569: E/PluginManager(23862): at android.app.ActivityThread.main(ActivityThread.java:4517)
06-04 13:14:45.569: E/PluginManager(23862): at java.lang.reflect.Method.invokeNative(Native Method)
06-04 13:14:45.569: E/PluginManager(23862): at java.lang.reflect.Method.invoke(Method.java:511)
06-04 13:14:45.569: E/PluginManager(23862): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:993)
06-04 13:14:45.569: E/PluginManager(23862): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:760)
06-04 13:14:45.569: E/PluginManager(23862): at dalvik.system.NativeStart.main(Native Method)
06-04 13:14:45.589: E/AndroidRuntime(23862): FATAL EXCEPTION: main
06-04 13:14:45.589: E/AndroidRuntime(23862): java.lang.RuntimeException: Error receiving broadcast Intent { act=android.net.conn.CONNECTIVITY_CHANGE flg=0x10000010 (has extras) } in org.apache.cordova.networkinformation.NetworkManager$1@4181a808
06-04 13:14:45.589: E/AndroidRuntime(23862): at android.app.LoadedApk$ReceiverDispatcher$Args.run(LoadedApk.java:737)
06-04 13:14:45.589: E/AndroidRuntime(23862): at android.os.Handler.handleCallback(Handler.java:605)
06-04 13:14:45.589: E/AndroidRuntime(23862): at android.os.Handler.dispatchMessage(Handler.java:92)
06-04 13:14:45.589: E/AndroidRuntime(23862): at android.os.Looper.loop(Looper.java:137)
06-04 13:14:45.589: E/AndroidRuntime(23862): at android.app.ActivityThread.main(ActivityThread.java:4517)
06-04 13:14:45.589: E/AndroidRuntime(23862): at java.lang.reflect.Method.invokeNative(Native Method)
06-04 13:14:45.589: E/AndroidRuntime(23862): at java.lang.reflect.Method.invoke(Method.java:511)
06-04 13:14:45.589: E/AndroidRuntime(23862): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:993)
06-04 13:14:45.589: E/AndroidRuntime(23862): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:760)
06-04 13:14:45.589: E/AndroidRuntime(23862): at dalvik.system.NativeStart.main(Native Method)
06-04 13:14:45.589: E/AndroidRuntime(23862): Caused by: java.lang.NullPointerException
06-04 13:14:45.589: E/AndroidRuntime(23862): at org.apache.cordova.networkinformation.NetworkManager.getConnectionInfo(NetworkManager.java:201)
06-04 13:14:45.589: E/AndroidRuntime(23862): at org.apache.cordova.networkinformation.NetworkManager.updateConnectionInfo(NetworkManager.java:171)
06-04 13:14:45.589: E/AndroidRuntime(23862): at org.apache.cordova.networkinformation.NetworkManager.access$0(NetworkManager.java:168)
06-04 13:14:45.589: E/AndroidRuntime(23862): at org.apache.cordova.networkinformation.NetworkManager$1.onReceive(NetworkManager.java:110)
06-04 13:14:45.589: E/AndroidRuntime(23862): at android.app.LoadedApk$ReceiverDispatcher$Args.run(LoadedApk.java:728)
06-04 13:14:45.589: E/AndroidRuntime(23862): ... 9 more
///////////////////////////////////////////
这是我的申请代码
///////////////////////////////////////////
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<meta name="format-detection" content="telephone=no" />
<!-- WARNING: for iOS 7, remove the width=device-width and height=device-height attributes. See https://issues.apache.org/jira/browse/CB-4323 -->
<meta name="viewport" content="user-scalable=no, initial-scale=1, maximum-scale=1, minimum-scale=1, width=device-width, height=device-height, target-densitydpi=device-dpi" />
<link rel="stylesheet" type="text/css" href="css/index.css" />
<meta name="msapplication-tap-highlight" content="no" />
<title>myapp</title>
</head>
<body>
<div class="app">
<div id="deviceready">
<p class="event listening"></p>
<p class="event received"></p>
<p id="connexion"></p>
</div>
</div>
<script type="text/javascript" src="cordova.js"></script>
<script type="text/javascript" src="js/index.js"></script>
<script type="text/javascript">
app.initialize();
//listener qui se déclenche dès que le mobile est prêt
//
document.addEventListener("deviceready", onDeviceReady , false);
function onDeviceReady() {
try{
checkConnection();
}
catch(e){
console.log(e);
}
}
function checkConnection() {
var networkState = navigator.connection.type;
var states = {};
states[Connection.UNKNOWN] = 'connexion de type inconnu';
states[Connection.ETHERNET] = 'connexion Ethernet';
states[Connection.WIFI] = 'connexion WiFi';
states[Connection.CELL_2G] = 'connexion 2G';
states[Connection.CELL_3G] = 'connexion 3G';
states[Connection.CELL_4G] = 'connexion 4G';
states[Connection.CELL] = 'connexion generique';
states[Connection.NONE] = 'pas de connexion internet';
document.getElementById('connexion').innerHTML='type de la connexion internet : ' +states[networkState];
}
</script>
</body>
</html>
答案 0 :(得分:1)
我有同样的问题,这解决了我的问题:
cordova plugin rm org.apache.cordova.network-information
cordova plugin add https://github.com/apache/cordova-plugin-network-information
答案 1 :(得分:0)
我花了一整天才解决这个问题。我所做的是,将 NetworkManager.java 替换为正在运行的旧项目中的相同文件。 现在它在应用程序离线时不会崩溃。
答案 2 :(得分:0)
这是一个插件问题。 https://issues.apache.org/jira/browse/CB-6907
跑步
cordova plugin rm org.apache.cordova.network-information
cordova plugin add https://github.com/apache/cordova-plugin-network-information
像MazzCris建议的那样