8

The Connection to the server was unsuccessful(file:///android-asset/www/index.html)

is showing when i run my android application. please let me know how to resolve this issue.

manukv
  • 2,035
  • 18
  • 30
  • Can you add some code? like the code in your main activity file. is your index file inside assets directory? like : assets/www/index.html – Sanjay D May 07 '14 at 10:10
  • Possible duplicate of [Application Error - The connection to the server was unsuccessful. (file:///android\_asset/www/index.html)](http://stackoverflow.com/questions/12319809/application-error-the-connection-to-the-server-was-unsuccessful-file-andr) – Dunc Apr 08 '16 at 15:28

5 Answers5

25

For latest Cordova (4+) this a setting in config.xml:

e.g.

<preference name="LoadUrlTimeoutValue" value="70000"/>

Increases default timeout to 70 seconds (default is 20), reducing the chance of timing out.

Docs: https://cordova.apache.org/docs/en/latest/config_ref/index.html#preference

When loading a page, the amount of time to wait before throwing a timeout error.

Dunc
  • 17,414
  • 6
  • 80
  • 98
8

This may asked here many times.. This issue can fix by adding a timeout to the webview call (index.html). In your project_name.java class just add this

 super.setIntegerProperty("loadUrlTimeoutValue", 5000);

And in Cordova latest, just use this to timeout

 super.loadUrl(Config.getStartUrl(), 5000);

Also go through these so questions

Question1

Question2

UPDATE :

One more solution, try this

Create a main.html and put your code there, and in your index.html just redirect to main.html

<script>
 window.location='./main.html';
</script>
Community
  • 1
  • 1
manukv
  • 2,035
  • 18
  • 30
  • manukv thanks for ur answer but it will not work i am still getting the same error after modified my .java class.please let me know any other solution –  May 07 '14 at 10:41
  • which cordova version are you using and are you trying to run app in emulator or device?? answer updated pls check it – manukv May 07 '14 at 11:55
4

This blog post from Robert Kehoe:

  • Seemed to be EASY to me
  • Made sense to me
  • WORKED for me

Rename your index.html to "main.html"

Create a new "index.html" and put the following content into it:

<!doctype html>
<html>
  <head>
   <title>the title</title>
   <script>
     window.location='./main.html';
   </script>
  <body>
  </body>
</html>

Rebuild your app! No more errors!

Robert also said,

Another good idea is to give your application a “splash screen”, so that the user gets instant feedback that your app is loading/working, before it is fully ready.

2

The main problem for this issue is take more time to load your page.

yes it's can a hack to solve this issue, make a html page name index.html and your existing index page name to be change as a main.html or any other one give a redirection to this page like this

    <script>
       window.location='main.html';
    </script>

am sure it's work very much

LeNI
  • 1,144
  • 2
  • 10
  • 18
0

hey i think this error may come load multiple script in starting time so it will take more time.

so you set like this in your java...

super.loadUrl("file:///android_asset/www/index.html");
super.setIntegerProperty("loadUrlTimeoutValue", 600000);

reference1 reference2

Community
  • 1
  • 1
kathir
  • 4,219
  • 3
  • 16
  • 29