Cordova Connection to server was Unsuccessful
Asked Answered
N

5

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.

Norrisnorrv answered 7/5, 2014 at 10:0 Comment(2)
Can you add some code? like the code in your main activity file. is your index file inside assets directory? like : assets/www/index.htmlBobine
Possible duplicate of Application Error - The connection to the server was unsuccessful. (file:///android_asset/www/index.html)Galwegian
G
26

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.

Galwegian answered 8/4, 2016 at 15:22 Comment(3)
This one solved my problem for the latest version of Cordova. Much more simple than other workarounds.Aiden
were to add this tagTrichinosis
In config.xml, in the root folder of your projectHeadway
A
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>
Andino answered 7/5, 2014 at 10:11 Comment(2)
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 solutionNorrisnorrv
which cordova version are you using and are you trying to run app in emulator or device?? answer updated pls check itAndino
F
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.

Flung answered 19/2, 2016 at 17:55 Comment(2)
Sadly I don't have cordova and its plugins injected into main.htmlStroman
In my case, it's the splash screen that's timing out. :-(Scudo
H
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

Hazlitt answered 7/5, 2014 at 11:55 Comment(0)
N
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

Negrete answered 7/5, 2014 at 10:13 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.