我使用phonegap 1.3.0开发移动应用程序。 当我点击一个按钮调用我的插件来调用js函数时,大约20秒后,反击错误:“E / DroidGap(21383):DroidGap:TIMEOUT ERROR! - 在eclipse日志控制台中调用webViewClient”。 并且模拟器警告对话框,显示错误消息:与服务器的连接不成功。(javascript:showProcessBar(1)) 我该如何修复错误?谢谢!
下面有一些细节可以补充我的问题。 当我在phonegap插件中调用js函数时。必须在logcat中显示错误信息:“E / DroidGap(21383):DroidGap:TIMEOUT ERROR! - 调用webViewClient”。
我找到了生成错误的代码。就在下面:
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);因为它会提醒对话框终止我的程序。
答案 0 :(得分:1)
Android在网页浏览中加载网址时会执行超时。
看看这个链接,(它并不真正属于JQM),但是phonegap android http://jquerymobile.com/test/docs/pages/phonegap.html
答案 1 :(得分:0)
问题解释了......当任何PhoneGap调用外部URL时出现time out
响应时,它会抛出该错误。
您可以使用此HTML5功能检查互联网连接:
navigator.onLine;
您可以在此处看到它:http://html5demos.com/nav-online
答案 2 :(得分:0)
super.setIntegerProperty( “loadUrlTimeoutValue”,60000);
将此行放在Activity
中的java代码中