【问题标题】:A network error in Phonegap on Android?Android上Phonegap中的网络错误?
【发布时间】:2012-08-01 11:53:04
【问题描述】:

我收到此错误。我该怎么办?

路径有效,我已经检查过了。我已经干净并再次重建了应用程序,等等。我真的不知道接下来该怎么办!

在我的活动课程中,我有以下代码:

import android.app.Activity;
import android.os.Bundle;
import org.apache.cordova.*;

public class TestPhoneGapActivity extends DroidGap {
    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
       // setContentView(R.layout.main);
        String url = "file:///assets/www/index.html"; 
        super.loadUrl(url); 
    }
}

【问题讨论】:

  • 这种情况什么时候发生?除了图片,你还有什么错误LOG吗?
  • super.loadUrl("file:///android_asset/www/index.html");
  • 确保您已将 html 和 js 文件适当地放入项目文件夹中。

标签: android eclipse cordova


【解决方案1】:

我遇到了这个问题,然后我就这样解决了..

super.loadUrl("file:///android_asset/www/index.html"); 

super.loadUrl("file:///android_asset/www/index.htm");

【讨论】:

    【解决方案2】:

    您可能需要使用 IceCreamCordovaWebViewClient

    @Override
        public void init() {
        super.init(webView, new IceCreamCordovaWebViewClient(this, webView), new CordovaChromeClient(this, webView));
    }
    

    【讨论】:

      【解决方案3】:

      检查您的资产/www/ 文件夹。检查 index.html 文件是否存在。

      【讨论】:

        【解决方案4】:

        我在网上找到了一个非常好的解决方案。

        您基本上需要做的就是将 index.html 的内容移动到另一个文件,比如 app.html。

        然后在你原来的 index.html 中有如下代码:

        <!doctype html>
        <html>
        <head>
           <title>your app name</title>
        </head>
        <body>
           <script>
               window.location='./app.html';
           </script>
        </body>
        </html>
        

        与服务器的连接不会再超时,应用应该会成功加载。

        现在我没有想出这个好主意。所有功劳归功于罗伯特·基欧:

        https://www.robertkehoe.com/2013/01/fix-for-phonegap-connection-to-server-was-unsuccessful/

        这样做帮助我解决了我自己的 Android phonegap 应用程序的类似问题...

        【讨论】:

          【解决方案5】:

          检查你的 www 文件夹,我认为那里没有 index.hmtl

          【讨论】:

          • 为什么要复活一个 3 年前与旧答案重复的旧问题?
          • index. hmtl?真的吗?
          【解决方案6】:

          Raj Patel 回答有效!应该使用 super.loadUrl("file:///android_asset/www/index.html");虽然eclipse中调用assets中的文件夹

          【讨论】:

          • 我遇到了类似的错误,除了我已经有“super.loadUrl("file:///android_asset/www/index.html");”设置:/
          猜你喜欢
          • 1970-01-01
          • 2016-04-29
          • 1970-01-01
          • 1970-01-01
          • 2014-08-25
          • 1970-01-01
          • 2020-08-22
          • 1970-01-01
          • 1970-01-01
          相关资源
          最近更新 更多