【问题标题】:E/DroidGap(21383): DroidGap: TIMEOUT ERROR! - calling webViewClientE/DroidGap(21383):DroidGap:超时错误! - 调用 webViewClient
【发布时间】:2012-02-12 05:08:37
【问题描述】:

我使用 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);因为它会提醒一个对话框来终止我的程序。

【问题讨论】:

标签: android cordova webkit webviewclient


【解决方案1】:

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

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

【讨论】:

    【解决方案2】:

    问题自行解决。当任何 PhoneGap 对外部 URL 的调用中有 time out 响应时,它会引发该错误。

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

    navigator.onLine;
    

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

    【讨论】:

      【解决方案3】:

      super.setIntegerProperty("loadUrlTimeoutValue",60000);

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

      【讨论】:

        猜你喜欢
        • 2013-08-09
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2012-02-29
        • 1970-01-01
        • 1970-01-01
        • 2012-06-29
        • 1970-01-01
        相关资源
        最近更新 更多