Android E/DroidGap(21383):DroidGap:超时错误!-调用webViewClient
我使用phonegap 1.3.0开发移动应用程序。 当我点击一个按钮来调用我的插件来调用js函数时,大约20秒后,我在eclipse日志控制台中反驳了错误:“E/DroidGap(21383):DroidGap:TIMEOUT error!-调用webViewClient”。 并且仿真器警告一个对话框,显示错误消息:与服务器的连接未成功。(javascript:showProcessBar(1)) 我如何修复错误?谢谢 下面有一些细节来补充我的问题。 当我在phonegap插件中调用js函数时。必须在logcat中显示错误消息:“E/DroidGap(21383):DroidGap:超时错误!-调用webViewClient” 我找到了产生错误的代码。就在下面:Android E/DroidGap(21383):DroidGap:超时错误!-调用webViewClient,android,cordova,webkit,webviewclient,Android,Cordova,Webkit,Webviewclient,我使用phonegap 1.3.0开发移动应用程序。 当我点击一个按钮来调用我的插件来调用js函数时,大约20秒后,我在eclipse日志控制台中反驳了错误:“E/DroidGap(21383):DroidGap:TIMEOUT error!-调用webViewClient”。 并且仿真器警告一个对话框,显示错误消息:与服务器的连接未成功。(javascript:showProcessBar(1)) 我如何修复错误?谢谢 下面有一些细节来补充我的问题。 当我在phonegap插件中调用js函数时
private void loadUrlIntoView(final String url) {
if (!url.startsWith("javascript:")) {
LOG.d(TAG, "DroidGap.loadUrl(%s)", url);
}
this.url = url;
if (this.baseUrl == null) {
int i = url.lastIndexOf('/');
if (i > 0) {
this.baseUrl = url.substring(0, i+1);
}
else {
this.baseUrl = this.url + "/";
}
}
if (!url.startsWith("javascript:")) {
LOG.d(TAG, "DroidGap: url=%s baseUrl=%s", url, baseUrl);
}
// Load URL on UI thread
final DroidGap me = this;
this.runOnUiThread(new Runnable() {
public void run() {
// Init web view if not already done
if (me.appView == null) {
me.init();
}
// Handle activity parameters
me.handleActivityParameters();
// Track URLs loaded instead of using appView history
me.urls.push(url);
me.appView.clearHistory();
// Create callback server and plugin manager
if (me.callbackServer == null) {
me.callbackServer = new CallbackServer();
me.callbackServer.init(url);
}
else {
me.callbackServer.reinit(url);
}
if (me.pluginManager == null) {
me.pluginManager = new PluginManager(me.appView, me);
}
else {
me.pluginManager.reinit();
}
// If loadingDialog property, then show the App loading dialog for first page of app
String loading = null;
if (me.urls.size() == 1) {
loading = me.getStringProperty("loadingDialog", null);
}
else {
loading = me.getStringProperty("loadingPageDialog", null);
}
if (loading != null) {
String title = "";
String message = "Loading Application...";
if (loading.length() > 0) {
int comma = loading.indexOf(',');
if (comma > 0) {
title = loading.substring(0, comma);
message = loading.substring(comma+1);
}
else {
title = "";
message = loading;
}
}
me.spinnerStart(title, message);
}
// Create a timeout timer for loadUrl
final int currentLoadUrlTimeout = me.loadUrlTimeout;
Runnable runnable = new Runnable() {
public void run() {
try {
synchronized(this) {
wait(me.loadUrlTimeoutValue);
}
} catch (InterruptedException e) {
e.printStackTrace();
}
// If timeout, then stop loading and handle error
if (me.loadUrlTimeout == currentLoadUrlTimeout) {
me.appView.stopLoading();
LOG.e(TAG, "DroidGap: TIMEOUT ERROR! - calling webViewClient");
//me.webViewClient.onReceivedError(me.appView, -6, "The connection to the server was unsuccessful.", url);
}
}
};
Thread thread = new Thread(runnable);
thread.start();
me.appView.loadUrl(url);
}
});
}
我对以下行进行注释:me.webViewClient.onReceivedError(me.appView,-6,“与服务器的连接不成功”,url);因为它会提醒对话框终止我的程序。问题自行解释。。当对外部URL的任何PhoneGap调用中出现超时时,它会抛出该错误 您可以使用此HTML5功能来检查internet连接:
navigator.onLine;
您可以看到它在这里工作:Android在Web视图中加载URL时强制超时 请查看此链接(它实际上与JQM无关),但是phonegap android super.setIntegerProperty(“loadUrlTimeoutValue”,60000) 将这一行放在活动的java代码中这可能会有帮助: