5

I am developing a android app using phonegap, it calls a website (http://siteaddress.com:8081) to get json encoded data. This is working fine on the emulator, then I built the android package .apk file using phonegap build but when i installed this package on my android phone and started the app, it force closes the application showing the error "The connection to the server was unsuccessful.(file:///android_asset/www/index.html)".

I have built the app using phonegap build, passed it the index.html as well as tried the .zip file package but still getting this error. I tried searching for this error and also included the below code in my app as suggested on some sites but still it is giving error.

super.setBooleanProperty("loadInWebView", true);
super.setIntegerProperty("loadUrlTimeoutValue", 60000);

Has this got something to do with the website that i am trying to call from my app? I tried opening that site in the mobile browser but it didn't opened but the website works fine on a desktop browser. Is there something wrong that i am doing?

Arif
  • 206
  • 2
  • 3
  • 9

3 Answers3

3

The following code snippet solved my problem

    @Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    super.loadUrl("file:///android_asset/www/home/index.html");
    super.setIntegerProperty("loadUrlTimeoutValue", 10000); 

I have added

super.setIntegerProperty("loadUrlTimeoutValue", 10000); 

to the com.mypackage.xxx.java file for 10 sec waiting time

Thomas V J
  • 638
  • 8
  • 7
3

I'm guessing its the port number your using. Have you tried using port 80 for your server rather than 8081? Its possible that port isn't open on your device.

Mike P
  • 2,547
  • 2
  • 20
  • 25
  • It worked... This is strange since the url works in a desktop browser. Anyways, thanks a lot. – Arif Oct 04 '11 at 08:49
  • Your welcome, I suspect its because your mobile device or the network is being more restrictive on which ports are open than your desktop. – Mike P Oct 04 '11 at 14:58
  • 1
    I had a debugging script loading on port 8081. Removing that fixed my problem. – CoatedMoose Jul 16 '12 at 02:20
2

*I had Same problem solved by referring * this link...

This error occurs bcoz of Server connection timeout so, Has mentioned in above post u can give 10 sec delay in that time put some splash screen..

Pradeep
  • 2,466
  • 25
  • 37
  • 1
    Yip, this also solved it for me. For the record, it seems as if this problem kicks in when you do (a lot?) of network requests with from the app main page - so loading with an almost empty page and then jumping to the "real" page seems to fool the system into behaving. Thanks Pradeep! – demaniak Oct 16 '13 at 07:07