您的位置:首页 > 移动开发

Application Error - The connection to the server was unsuccessful.

2018-03-07 18:03 423 查看
问题:
Application Error - The connection to the server was unsuccessful.(file://android-asset/www/index.html)
解决:
参考原网址: http://blog.csdn.net/qq_20473985/article/details/68490438 http://blog.csdn.net/zhanqizi/article/details/41349959

正文:
最近用phonegap封装前端页面做的项目时,遇到一个问题,分享一下,希望可以帮到有同样问题的朋友。
在启动应用时会报错:
Application Error - The connection to the server was unsuccessful. (file:///android_asset/www/index.html)
导致这个错误的原因是:在安卓load页面时,页面需要加载的内容没有加载完。
所以需要增加超时时间,或加一个过渡页来避免这个问题。
方案如下:
1.在load页面时,先load一个空的页面,当页面load完成时,再加载现在的index.html,
步骤如下: 1)将你的"index.html"改名为"main.html";
2)创建一个新的"index.html",把下面的内容放到"index.html"中, <script type="text/javascript"> window.location="./main.html"; </script>.2.将LoadUrlTimeoutValue设置为50或60秒,默认是20秒(此方案只能减少这个错误,无法从源头解决问题),
在config.xml中增加下面这行:<preference name="loadUrlTimeoutValue" value="50000" />
注:第二种方案只会减少产生这种错误,但不会从根本上避免这个问题,所以建议使用第一种方法,第二种可以作为辅助手段。
如果是在中间弹出的这个错误框,可能是由以下原因导致的:
The problem is likely due to the speed of the emulator so the network is too slow complete the communication
in a timely fashion.This can be due to:as you said you made some UI modifications, may be the size of images
are high)2.Your script may have a infinite or long loop, so that it takes too much of time to load.3.
You will be using too much of scripts (jQuery, iscroll, etc etc.. more number of plugins or scripts )
超时引起的问题可以增加超时时间,增加loadUrlTimeoutValue的值;如果是由图片引起的,建议可以通过降低图片的色位,大小等。

3)设置加载超时属性,在activity的onCreate方法中加入一行代码 
 @Overridepublic void onCreate(Bundle savedInstanceState) {
     super.onCreate(savedInstanceState); 
    super.loadUrl("file:///android_asset/www/home/index.html"); 
    super.setIntegerProperty("loadUrlTimeoutValue", 10000);  
    或
    super.setIntegerProperty("loadUrlTimeoutValue", 60000);

内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: 
相关文章推荐