简体   繁体   中英

Application error: there was a network error(file:///assets/www/index.html

I am trying to run a phonegap application on eclipse juno. The android version is 4.1.2. The application gives an error saying:

Application error: there was a network error(file:///assets/www/index.html when i try to run the app.

The android manifest is as follows

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android" android:windowSoftInputMode="adjustPan"
      package="com.initial.belgium" android:versionName="1.0" android:versionCode="1" android:hardwareAccelerated="true">
    <supports-screens
        android:largeScreens="true"
        android:normalScreens="true"
        android:smallScreens="true"
        android:xlargeScreens="true"
        android:resizeable="true"
        android:anyDensity="true"
        />

    <uses-permission android:name="android.permission.CAMERA" />
    <uses-permission android:name="android.permission.VIBRATE" />
    <uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
    <uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
    <uses-permission android:name="android.permission.ACCESS_LOCATION_EXTRA_COMMANDS" />
    <uses-permission android:name="android.permission.INTERNET" />
    <uses-permission android:name="android.permission.RECEIVE_SMS" />
    <uses-permission android:name="android.permission.RECORD_AUDIO" />
    <uses-permission android:name="android.permission.RECORD_VIDEO"/>
    <uses-permission android:name="android.permission.MODIFY_AUDIO_SETTINGS" />
    <uses-permission android:name="android.permission.READ_CONTACTS" />
    <uses-permission android:name="android.permission.WRITE_CONTACTS" />   
    <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />   
    <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
    <uses-permission android:name="android.permission.GET_ACCOUNTS" />
    <uses-permission android:name="android.permission.BROADCAST_STICKY" />


    <application android:icon="@drawable/icon" android:label="@string/app_name"
        android:hardwareAccelerated="true"
        android:debuggable="true">
        <activity android:name="belgium" android:label="@string/app_name"
                android:theme="@android:style/Theme.Black.NoTitleBar"
                android:configChanges="orientation|keyboardHidden|keyboard|screenSize|locale">
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />
                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
    </application>

    <uses-sdk android:minSdkVersion="7" android:targetSdkVersion="16"/>
</manifest> 

The java source is as follows:

package com.initial.belgium;

import android.os.Bundle;
import org.apache.cordova.*;

public class belgium extends DroidGap
{
    @Override
    public void onCreate(Bundle savedInstanceState)
    {
        super.onCreate(savedInstanceState);
        super.loadUrl("file:///assets/www/index.html"); 
    }
}

Could someone help me fix this?? Thanks

Try changing:

super.loadUrl("file:///assets/www/index.html");

To:

super.loadUrl("file:///android_asset/www/index.html");

For me the issue was that the Phonegap "Hello World" tutorial for Android simply does not work. It created a sub-folder under platforms / android / assets called "phonegap-app-hello-world-3.1.0". This folder is where all the files were, so once I changed the loadUrl parameter to reflect that it loaded without the error:

super.loadUrl("file:///android_asset/www/phonegap-app-hello-world-3.1.0/www/index.html");

Hope this helps someone, would have saved me a couple of hours of mucking around!

I found a really good solution to this online.

What you basically need to do is to move the contents of index.html to another file, say app.html.

Then have the following code in your original index.html:

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

The connection to the server won't timeout anymore and the app should load successfully.

Now I didn't come up with this great idea. All credit goes to Robert Kehoe:

https://www.robertkehoe.com/2013/01/fix-for-phonegap-connection-to-server-was-unsuccessful/

Doing this helped me solve a similar problem with my own Android phonegap application...

.loadUrl should take a url that is pointing to a server. Change it to http://www.google.com/ and it should work.

To use your own files, upload them to a web server or start one on your local machine. If you are on a mac, there is one built-in (simply enable Web Sharing from System Setting). Or if you have Python installed, you can run python -m SimpleHTTPServer from the /assets/www directory, and then change the URL to 'http://localhost:8000/index.html'

For me, this problem was caused by the fact that I edited and renamed both an index.html file and an app.js file. When I renamed I included the extension .html and .js. This caused the files to be renamed to index.html.html and app.js.js. So clearly the project could not find the files it was looking for. I believe this is a manifestation of the answers given above.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM