应用程序错误 - 与服务器的连接失败。(file:///android_asset/www/index.html)
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/12319809/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Application Error - The connection to the server was unsuccessful. (file:///android_asset/www/index.html)
提问by Soufiene
App Dies On Startup (connection to the server was unsuccessful)
应用程序在启动时死亡(连接到服务器不成功)
I have an Android application that I'm writing using PhoneGap BUILD. The app was working fine earlier, but now it seems I am getting this error after refining my app (some UI changes only)
我有一个正在使用 PhoneGap BUILD 编写的 Android 应用程序。该应用程序之前运行良好,但现在似乎我在优化我的应用程序后收到此错误(仅某些 UI 更改)
1) When I start the app I (usually) get:
1)当我启动应用程序时,我(通常)得到:
Application Error - The connection to the server was unsuccessful. (file:///android_asset/www/index.html)
应用程序错误 - 与服务器的连接失败。(file:///android_asset/www/index.html)
Sorry if this is duplication of any question. I have seen some similar questions here, but i couldn't find a perfect answer or solution. As in my case it was working fine until my last changes.
对不起,如果这是任何问题的重复。我在这里看到了一些类似的问题,但我找不到完美的答案或解决方案。和我的情况一样,在我最后一次更改之前它工作正常。
采纳答案by AnhSirk Dasarp
As you said, there are many duplicate questions on the same topic. Any how explaining your situation.
正如您所说,同一主题有许多重复的问题。任何如何解释你的情况。
The problem might be solved by adding a timeout to call your index.html
可以通过添加超时来调用您的 index.html 来解决该问题
ie you need to add super.setIntegerProperty("loadUrlTimeoutValue", 70000);
in your activity.java file ( inside src/com/yourProj/--/youractivity.java)
above this line: super.loadUrl("file:///android_asset/www/index.html");
即你需要super.setIntegerProperty("loadUrlTimeoutValue", 70000);
在你的 activity.java 文件(在 src/com/yourProj/--/youractivity.java 中)添加到这一行上面: super.loadUrl("file:///android_asset/www/index.html");
Explanation:
解释:
This can be happened due to the following reasons
这可能是由于以下原因造成的
The core reason: 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:
这可能是由于:
- Your code/data/image is of too much of size ( I guess in your case you are using some images ,as you said you made some UI modifications, may be the size of images are high)
- Your script may have a infinite or long loop, so that it takes too much of time to load.
- You will be using too much of scripts (jQuery, iscroll, etc etc.. more number of plugins or scripts )
- 您的代码/数据/图像太大了(我猜在您的情况下您正在使用一些图像,正如您所说,您进行了一些 UI 修改,可能是图像的尺寸很大)
- 您的脚本可能有一个无限循环或长循环,因此加载时间太长。
- 您将使用过多的脚本(jQuery、iscroll 等。更多的插件或脚本)
回答by Soufiene
In your config.xml file add this line:
在您的 config.xml 文件中添加以下行:
<preference name="loadUrlTimeoutValue" value="700000" />
回答by Robin C Samuel
Here is the working solution
这是工作解决方案
create a new page main.html
创建一个新页面 main.html
example:
例子:
<!doctype html>
<html>
<head>
<title>tittle</title>
<script>
window.location='./index.html';
</script>
</head>
<body>
</body>
</html>
change the following in mainactivity.java
在 mainactivity.java 中更改以下内容
super.loadUrl("file:///android_asset/www/index.html");
to
到
super.loadUrl("file:///android_asset/www/main.html");
Now build your application and it works on any slow connection
现在构建您的应用程序,它适用于任何慢速连接
参考。
NOTE: This is a workaround I found in 2013.
注意:这是我在 2013 年发现的一种解决方法。
回答by sharma_kunal
Please remove remotely linked jQuery files such as:
https://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js
请删除远程链接的 jQuery 文件,例如:
https://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js
Instead, download this file and load it from your local js folder, making the URI:
相反,下载此文件并从本地 js 文件夹加载它,使 URI:
js/jquery.min.js
js/jquery.min.js
回答by Raugaral
Remove the external scripts in your index.html
删除 index.html 中的外部脚本
Change this:
改变这个:
<script src="http://code.highcharts.com/highcharts-more.js"></script>
to
到
<script src="project_folder/highcharts-more.js"></script>
回答by Avinash
I had a similar issue and based on above suggestions I first added "super.setIntegerProperty("loadUrlTimeoutValue", 70000);" but that did not help. So I tried Project -> Clean, that worked and I can launch the app now !
我有一个类似的问题,根据上述建议,我首先添加了“super.setIntegerProperty("loadUrlTimeoutValue", 70000);” 但这没有帮助。所以我尝试了 Project -> Clean,它起作用了,我现在可以启动应用程序了!
Avinash...
阿维纳什...
回答by Nithin Krishnan P
Try this,
尝试这个,
1.Rename your index.html to “main.html”
2.Create a new “index.html” and put the following content into it:
<!doctype html> <html> <head> <title>tittle</title> <script> window.location='./main.html'; </script> <body> </body> </html>
3.Rebuild your app! No more errors!
1.将你的index.html重命名为“main.html”
2.新建一个“index.html”,放入如下内容:
<!doctype html> <html> <head> <title>tittle</title> <script> window.location='./main.html'; </script> <body> </body> </html>
3.重建你的应用程序!没有更多的错误!
回答by Deano
I had the same on my project.
我在我的项目中也有同样的情况。
I tried " super.setIntegerProperty("loadUrlTimeoutValue", 70000); " but to no avail.
我试过“ super.setIntegerProperty("loadUrlTimeoutValue", 70000); ”但无济于事。
I ensured all files were linked properly [ CSS, JS files etc ], validated the HTML using w3c validator [ http://validator.w3.org/#validate_by_upload] , and cleaned the project [ Project -> Clean ]
我确保所有文件都正确链接 [CSS、JS 文件等],使用 w3c 验证器 [ http://validator.w3.org/#validate_by_upload]验证 HTML ,并清理项目 [Project -> Clean]
It now loads and executes without the same error.
它现在加载和执行没有同样的错误。
Hope this helps
希望这可以帮助
回答by jjyepez
Extending loading Timeout Limit will not solve the problem which caused the error, it just will avoid the system to show the message but performance will be affected whatsoever.
延长加载超时限制不会解决导致错误的问题,它只会避免系统显示消息但性能会受到任何影响。
Actual reason: You may be linking files or images to remote locations, and those resources are taking too long to load. (this is likely the most common error)
实际原因:您可能将文件或图像链接到远程位置,而这些资源加载时间过长。(这可能是最常见的错误)
Definitive solution: move all the scripts, images and css needed to some local folders and load them locally ...
最终解决方案:将所需的所有脚本、图像和 css 移动到某些本地文件夹并在本地加载它们...
Performance will be increased and error will be effectively solved.
性能将得到提高,错误将得到有效解决。
回答by Alexey Muravyov
Check you index.html
file. If you use external resources, that not available when you run application then you can get this error.
检查你的index.html
文件。如果您使用运行应用程序时不可用的外部资源,则可能会出现此错误。
In my case I forgot to delete link on debugger script (weinre).
就我而言,我忘记删除调试器脚本(weinre)上的链接。
<script src="http://192.168.0.102:8080/target/target-script-min.js#anonymous"></script>
So application worked on emulator because http://192.168.0.102:8080/
was on my localhost and available for emulator.
所以应用程序在模拟器http://192.168.0.102:8080/
上工作,因为它在我的本地主机上并且可用于模拟器。
But when I setup application on mobile phone I had same error, because 192.168.0.102 was not available from mobile network.
但是当我在手机上设置应用程序时,我遇到了同样的错误,因为 192.168.0.102 无法从移动网络获得。