2

我使用 phonegap 1.3.0 开发移动应用程序。当我单击一个将调用我的插件以调用 js 函数的按钮时,大约 20 秒后,在 Eclipse 日志控制台中解决了错误:“E/DroidGap(21383): DroidGap: TIMEOUT ERROR! - calling webViewClient”。模拟器会弹出一个对话框,显示错误消息:与服务器的连接不成功。(javascript:showProcessBar(1)) 如何修复该错误?谢谢!

下面有一些细节可以补充我的问题。当我在 phonegap 插件中调用 js 函数时。必须在 logcat 中显示错误消息:“E/DroidGap(21383): DroidGap: TIMEOUT ERROR! - calling 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, "The connection to the server was unsuccessful.", url); 因为它会提醒一个对话框来终止我的程序。

4

3 回答 3

1

在 webview 中加载 URL 时,Android 会强制执行超时。

查看此链接,(它实际上与 JQM 无关),但 phonegap android http://jquerymobile.com/test/docs/pages/phonegap.html

于 2012-04-10T18:55:54.503 回答
0

问题本身就说明了......当time out任何 PhoneGap 调用对外部 URL 有响应时,它会引发该错误。

您可以使用此 HTML5 功能来检查互联网连接:

navigator.onLine;

你可以在这里看到它的工作:http: //html5demos.com/nav-online

于 2012-03-08T16:46:47.540 回答
0

super.setIntegerProperty("loadUrlTimeoutValue",60000);

将此行放在Activity中的java代码中

于 2012-05-25T04:05:49.073 回答