Application Error - The connection to the server was unsuccessful. (file:///and

Application Error - The connection to the server was unsuccessful. (file:///android_asset/www/index.html)

问题描述:
PhoneGap+Sencha Touch开发的应用,打包后的APP或者调试期间,在启动的时候提示如下信息:
Application Error - The connection to the server was unsuccessful.
(file:///android_asset/www/index.html)

问题分析:
这个应该是PhoneGap某些版本的BUG,尤其在index.html加载的内容较多时容易出现。

解决方法:
方法1:更新到PhoneGap的最新版本;
方法2:设置加载超时属性

super.setIntegerProperty("loadUrlTimeoutValue",10000); 

完整代码如下(设置超时为 10 秒)

@Override
publicvoid onCreate(Bundle savedInstanceState){
    super.onCreate(savedInstanceState);
    super.loadUrl("file:///android_asset/www/home/index.html");
    super.setIntegerProperty("loadUrlTimeoutValue",10000);
}


方法3:改名法
把index.html更名为main.html,然后新建一个index.html页面,内容如下:
<!doctype html> <html> <head> <title>tittle</title> <script> window.location='./main.html'; </script> <body> </body> </html>

主要原理就是通过一个过渡页面,把加载首页的内容最小化。

找到项目中res/xml目录下的config.xml,把你的外网的域名地址添加到配置中
<access origin="http://example.com" /> <!--allow any secure requests to example.com -->

方法四:
   index.html 里面https引用copy到本地,直接从本地引用,不通过http
    <!--script  src="https://cdn.rawgit.com/auth0/angular-storage/master/dist/angular-storage.js"></script-->

<script  src="lib/angular-storage/dist/angular-storage.js"></script>

猜你喜欢

转载自maxer025.iteye.com/blog/2390985