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

16

160

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.

Phantasy answered 7/9, 2012 at 14:10 Comment(0)
G
189

In your config.xml file add this line:

<preference name="loadUrlTimeoutValue" value="700000" />
Grenoble answered 13/7, 2015 at 7:42 Comment(6)
You should describe this as wellNacreous
For anyone wondering: It's the amount of time in milliseconds waited while loading the page before throwing an error: cordova.apache.org/docs/en/latest/config_ref/index.htmlOndine
<preference name="loadUrlTimeoutValue" value="120000" /> is better in compare with 700000, I mean if your app is not coming up in two minutes, then there is something wrong(and you should fix it by using another solution). Surly you don't want to wait about 11 minutes to see if an app is coming up or not!(that's why we do have timeout concept in the first place, right?:-)) According to the doc, default value is 20000 (20 seconds)Gomulka
i added this in my config file,but its not working on nexus 5xAlcine
This is so weird. I had mine set to 70000, and apps were dying after around 30 seconds of trying to load. I changed it to 120000 and now they load successfully in 3-4 seconds. That's all I changed. Argh.Tasiatasiana
I have tried this and also solved my problem but for a long time black screen comes for a long time i.e. near to 46 secBeadroll
A
24

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.

Aeriell answered 26/3, 2013 at 4:10 Comment(8)
Actually you just rename your index.html and create main.html with window.location = './index.html'. No need to change super.loadUrl from MainActivity.javaThaliathalidomide
Same effect! But your actual page will be changed to main.html. But I want my actually page to be index.html.BTW, I think your comment is wrong. You need to rename index.html to main.html and create a index.html page, then add window.location = './main.html'. in index.html page. This should work.Aeriell
Yes you right! I miss typed that one :D I meant that create index.html with window.location = './main.html'. :)Thaliathalidomide
Why you need your actual page to be index.html?Thaliathalidomide
@M.Salomaa, Nothing solid!! I just want to avoid confusion while running on a server. index.html will be automatically picked upon browsing to the project root :)Aeriell
This way you don't have cordova and plugins injected into pageDaliadalila
Why does this work? Sounds like snake-oil. And why is there no closing </head> tag?Pyatt
@Pyatt I answered this 4 years back. At that point, there were no reliable solutions to handle the delay caused when there are a lot of scripts to be loaded. So the app was crashing since the scripts delayed page load. This works because the main.html is light and has no scripts to load, thereby initializing the app faster, and then loading the scripts on index.html. The closing </head> was a typo, added now.Aeriell
C
10

Please remove remotely linked jQuery files such as: 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/jquery.min.js

Carillonneur answered 12/3, 2013 at 11:3 Comment(0)
R
6

Remove the external scripts in your index.html

Change this:

<script src="http://code.highcharts.com/highcharts-more.js"></script>

to

<script src="project_folder/highcharts-more.js"></script>
Rorry answered 16/3, 2016 at 14:4 Comment(0)
S
5

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 !

Avinash...

Scourings answered 11/4, 2014 at 10:43 Comment(0)
M
5

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!

Magnitude answered 25/9, 2015 at 6:4 Comment(4)
and what should i do if i have to add some arguments like main.html?USER=xxx&SESSION=xxx ?Brightness
window.location.href="./main.html?USER=xxx&SESSION=xxx"Magnitude
No cordova and plugins being injected into main.htmlDaliadalila
I have added this code but for approx 1 minute, a white screen is coming after splash. What should I do?Beadroll
A
5

fixing this on an ionic app, simply add

<preference name="loadUrlTimeoutValue" value="700000" />

to your config.xml file immediately after this line

<platform name="android">
Alegre answered 21/3, 2019 at 6:49 Comment(0)
C
4

I had the same on my project.

I tried " super.setIntegerProperty("loadUrlTimeoutValue", 70000); " but to no avail.

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 ]

It now loads and executes without the same error.

Hope this helps

Caligula answered 23/1, 2013 at 10:6 Comment(0)
A
4

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 ...

Performance will be increased and error will be effectively solved.

Agnesagnese answered 18/1, 2017 at 8:39 Comment(0)
S
4

Check you index.html file. If you use external resources, that not available when you run application then you can get this error.

In my case I forgot to delete link on debugger script (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.

But when I setup application on mobile phone I had same error, because 192.168.0.102 was not available from mobile network.

Shrinkage answered 24/2, 2017 at 22:14 Comment(0)
A
2

For my case, the problem was due to losing of the internet connection in my WiFi.

Arabesque answered 3/4, 2018 at 12:10 Comment(0)
T
1

In my case I am using ionic and I simply closed the dialog went to apps in the emulator and ran my app from there instead. This worked. I got the idea of that from here since it was just a time out issue.

Trauma answered 17/5, 2014 at 3:42 Comment(0)
R
1

If you are using visual studio. After changing config.xml sometimes you need this

clean build solution rebuild your app

It is working for me.

Rosalindarosalinde answered 3/4, 2017 at 6:52 Comment(0)
C
1

I was facing the same issue. I noticed that in my index i had both the "on device ready" and the "document.ready" function, so removing one of them fixed my problem :)

Cystitis answered 30/10, 2018 at 14:19 Comment(0)
L
0

It's quite a niche situation but thought I'd post it here in case it saves somebody else the hours I spent going round in circles.

I reverted to [email protected] after trying out [email protected] and started getting this error when trying to run my app in dev mode.

What I had forgotten is that when I upgraded to 10.0.1 I had to remove the whitelist plugin since it's now part of cordova-android.

Reinstating cordova-plugin-whitelist got everything working again for me!

Laudable answered 6/8, 2021 at 11:59 Comment(0)
Z
-8

Another reason this error might occur is: there is no index.html in .../YourApp/www/ !

I just followed the ionic guide, and one of the steps is:

$ rm www/index.html

On iOS this is no problem as during the build the compiler takes some default HTML instead. However, when building for android, NO example index.html is used. Took me sometime to find out ("WHY does it work on iOS, but not on android...?)

Easy solution: create a index.html, save it under .../YourApp/www, rebuild ...et voila!

Zelma answered 5/6, 2014 at 15:3 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.