user1654414
user1654414

Reputation:

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.

Upvotes: 161

Views: 150410

Answers (16)

skmbr
skmbr

Reputation: 123

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!

Upvotes: 0

Professor
Professor

Reputation: 2154

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

Upvotes: 5

Abir.d
Abir.d

Reputation: 788

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 :)

Upvotes: 1

Chong Lip Phang
Chong Lip Phang

Reputation: 9279

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

Upvotes: 2

Robin C Samuel
Robin C Samuel

Reputation: 1225

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.

Upvotes: 24

caglabaran
caglabaran

Reputation: 121

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.

Upvotes: 1

Alexey Muravyov
Alexey Muravyov

Reputation: 1153

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.

Upvotes: 4

jjyepez
jjyepez

Reputation: 350

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.

Upvotes: 4

sharma_kunal
sharma_kunal

Reputation: 2192

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

Upvotes: 10

Raugaral
Raugaral

Reputation: 1323

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>

Upvotes: 6

Dirk
Dirk

Reputation: 2207

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!

Upvotes: -8

Soufiene
Soufiene

Reputation: 2218

In your config.xml file add this line:

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

Upvotes: 189

Nithin Krishnan P
Nithin Krishnan P

Reputation: 758

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!

Upvotes: 5

FernandoZ
FernandoZ

Reputation: 438

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.

Upvotes: 1

Avinash
Avinash

Reputation: 51

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

Upvotes: 5

Deano
Deano

Reputation: 363

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

Upvotes: 4

Related Questions