【问题标题】:Cordova Connection to server was UnsuccessfulCordova 与服务器的连接不成功
【发布时间】:2014-05-07 10:00:18
【问题描述】:

The Connection to the server was unsuccessful(file:///android-asset/www/index.html)

在我运行我的 android 应用程序时显示。 请告诉我如何解决此问题。

【问题讨论】:

标签: android cordova cordova-3 cordova-plugins


【解决方案1】:

对于最新的 Cordova (4+),这是config.xml 中的设置:

例如

<preference name="LoadUrlTimeoutValue" value="70000"/>

将默认超时时间增加到 70 秒(默认为 20 秒),减少超时的机会。

文档:https://cordova.apache.org/docs/en/latest/config_ref/index.html#preference

加载页面时,在抛出一个页面之前等待的时间 超时错误。

【讨论】:

  • 这个解决了我最新版本的 Cordova 的问题。比其他解决方法简单得多。
  • 要添加这个标签
  • 在 config.xml 中,在项目的根文件夹中
【解决方案2】:

这可能在这里问了很多次.. 可以通过向 webview 调用 (index.html) 添加超时来解决此问题。在你的 project_name.java 类中添加这个

 super.setIntegerProperty("loadUrlTimeoutValue", 5000);

在最新的 Cordova 中,只需使用它来超时

 super.loadUrl(Config.getStartUrl(), 5000);

也通过这些so问题

Question1

Question2

更新:

另一种解决方案,试试这个

创建一个 main.html 并将您的代码放在那里,然后在您的 index.html 中重定向到 main.html

<script>
 window.location='./main.html';
</script>

【讨论】:

  • manukv 感谢您的回答,但它不起作用我在修改我的 .java 类后仍然遇到同样的错误。请让我知道任何其他解决方案
  • 您使用的是哪个科尔多瓦版本,您是否尝试在模拟器或设备中运行应用程序?回答更新请检查它
【解决方案3】:

This blog post 来自 Robert Kehoe:

  • 对我来说似乎很容易
  • 对我来说很有意义
  • 为我工作

将 index.html 重命名为“main.html”

新建一个“index.html”,将以下内容放入其中:

<!doctype html>
<html>
  <head>
   <title>the title</title>
   <script>
     window.location='./main.html';
   </script>
  <body>
  </body>
</html>

重建您的应用程序!没有更多错误!

罗伯特也说过

另一个好主意是为您的应用程序提供一个“启动画面”,以便用户在您的应用程序完全准备好之前立即获得关于您的应用程序正在加载/工作的反馈。

【讨论】:

  • 遗憾的是,我没有将 cordova 及其插件注入 main.html
  • 就我而言,是启动画面超时。 :-(
【解决方案4】:

此问题的主要问题是加载页面需要更多时间。

是的,可以通过 hack 来解决这个问题,创建一个 html 页面名称 index.html 和您现有的索引页面名称要更改为 main.html 或任何其他文件都会像这样重定向到此页面

    <script>
       window.location='main.html';
    </script>

我相信它非常有效

【讨论】:

    【解决方案5】:

    嘿,我认为这个错误可能会在开始时加载多个脚本,因此需要更多时间。

    所以你在你的java中这样设置...

    super.loadUrl("file:///android_asset/www/index.html");
    super.setIntegerProperty("loadUrlTimeoutValue", 600000);
    

    reference1 reference2

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多