Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

like image 394
silvanasono Avatar asked Dec 29 '14 21:12

silvanasono


People also ask

How do I enable JavaScript on WebView?

JavaScript is disabled in a WebView by default. You can enable it through the WebSettings attached to your WebView .You can retrieve WebSettings with getSettings() , then enable JavaScript with setJavaScriptEnabled() . WebView myWebView = (WebView) findViewById(R.id.webview);

How do I import WebView?

Modify src/MainActivity. java file to add WebView code. Run the application and choose a running android device and install the application on it and verify the results. Following is the content of the modified main activity file src/MainActivity.

How do you override a WebView?

If you want to override certain methods, you have to create a custom WebView class which extends WebView . Also, when you are inflating the WebView , make sure you are casting it to the correct type which is CustomWebView . CustomWebView webView = (CustomWebView) findViewById(R. id.

What is WebView implementation in Android?

Android WebView is a system component for the Android operating system (OS) that allows Android apps to display content from the web directly inside an application.


3 Answers

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.

like image 160
Samuele Bolognini Avatar answered Oct 16 '22 07:10

Samuele Bolognini


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.

like image 14
Nevada Williford Avatar answered Oct 16 '22 09:10

Nevada Williford


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.

like image 2
Alexiscanny Avatar answered Oct 16 '22 08:10

Alexiscanny