Application Error - The connection to the server was unsuccessful. (file:///android_asset/www/index.html)
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)
1) When I start the app I (usually) get:
Application Error - The connection to the server was unsuccessful. (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.
In your config.xml file add this line:
<preference name="loadUrlTimeoutValue" value="700000" />
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
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");
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 )
Here is the working solution
create a new page 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
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
refernce.
NOTE: This is a workaround I found in 2013.