silvanasono
silvanasono

Reputation: 394

On Android emulator, trying to load a webview i get net::err_cache_miss

I tried the example shown on Android developers website to show a webpage on a WebView component without success. The emulator shows the following error:

Webpage not available the webpage at http://developer.android.com could not be loaded because: net::ERR_CHACHE_MISS

I could not find any solution so far, even after looking on other threads on the web. I have also tried different links. I do not know if could be helpful in understanding the cause of this error, but the emulator is Nexus 4 API 21 with Android 5.0.1. I am using Android Studio 1.0.

The code is the same of the example:

In MainActivity.java:

protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);            
    setContentView(R.layout.activity_main);

    WebView myWebView = (WebView) findViewById(R.id.webview);
    WebSettings webSettings = myWebView.getSettings();
    webSettings.setJavaScriptEnabled(true);           
    myWebView.loadUrl("http://developer.android.com/");
}

In AndroidManifest:

<application
    android:allowBackup="true"
    android:icon="@drawable/ic_launcher"
    android:label="@string/app_name"
    android:theme="@style/AppTheme" >
    <uses-permission android:name="android.permission.INTERNET" />
.....

And in the view I have added the same code of the example

Example is on: http://developer.android.com/guide/webapps/webview.html

Upvotes: 25

Views: 28736

Answers (6)

JSav
JSav

Reputation: 11

Please paste the following outside the application tag in the AndroidManifest.xml

    <uses-permission android:name="android.permission.INTERNET"/>
    <uses-permission android:name="android.permission.CHANGE_NETWORK_STATE"/>
    <uses-permission android:name="android.permission.android.permission.ACCESS_NETWORK_STATE"/>

Upvotes: 1

Senthil
Senthil

Reputation: 21

Actually, the place of tag matters here. For example, this doesn't work:

    <activity android:name=".MainActivity"
        android:label="@string/app_name" >

        <intent-filter>
            <action android:name="android.intent.action.MAIN" />
            <category android:name="android.intent.category.LAUNCHER" />
        </intent-filter>
        <uses-permission android:name="android.permission.INTERNET" />
    </activity>

But below code works perfectly.

    <activity android:name=".MainActivity"
        android:label="@string/app_name" >
        <uses-permission android:name="android.permission.INTERNET" />
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />
            <category android:name="android.intent.category.LAUNCHER" />
        </intent-filter>
    </activity>

Upvotes: 2

Mediasoft
Mediasoft

Reputation: 281

Just include these Permissions in your AndroidManifest.xml

<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />

Upvotes: 1

Alexiscanny
Alexiscanny

Reputation: 579

I had the same error and I fixed with
inside the activity, like this:

<activity
        android:name=".MainActivity"
        android:label="@string/app_name" >
        <uses-permission android:name="android.permission.INTERNET" />
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />
            <category android:name="android.intent.category.LAUNCHER"/>
        </intent-filter>
</activity>

Because I build inside the main activity the webView.... I hope this will help someone else.

Upvotes: 2

Samuele Bolognini
Samuele Bolognini

Reputation: 651

Exactly, It has occured to me once and the solution was to put the following line: <uses-permission android:name="android.permission.INTERNET"/>

before the <application tag in the manifest.xml file.

Either that line is missing or it's misplaced (eg. at the end of the </manifest> tag.

Upvotes: 43

Nevada Williford
Nevada Williford

Reputation: 705

In case anyone else encounters this problem and since there isn't an answer here I thought I'd provide one.

For me it turned out to simply be the order the tags were in the manifest file. The user-permission element needs to appear before the application element. I just put it directly under the manifest element at the top and that seemed to do the trick for me.

Upvotes: 14

Related Questions