0

Could you help me? this is my first app and i don't know what i've done wrong.

i saw this solution but it did not help : Android Webview gives net::ERR_CACHE_MISS message

I've built it on Android Oreo but it gave the error message of the title.

What have i done so far:

I tried to change my androidmanifest.xml and put INTERNET in all-caps. I have checked the user permissions. I used a suggested version that works on 100% of devices (according to android studio).

this is my code so far. what did i do wrong?

mainactivity.Java :


import androidx.appcompat.app.AppCompatActivity;
import android.app.Activity;
import android.os.Bundle;
import android.view.KeyEvent;
import android.webkit.WebResourceRequest;
import android.webkit.WebSettings;
import android.webkit.WebView;
import android.os.Bundle;
import android.webkit.WebViewClient;

public class MainActivity extends AppCompatActivity {

    private WebView webView;

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

        webView = findViewById(R.id.webView);
        webView.getSettings().setBlockNetworkLoads(true);
        webView.getSettings().setJavaScriptEnabled(true);
        webView.loadUrl("https://agronotizie.imagelinenetwork.com/");
        webView.getSettings().setCacheMode(WebSettings.LOAD_NO_CACHE);



    }


}```



`<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent" >

    <WebView
        android:id="@+id/webView"
        android:layout_width="match_parent"
        android:layout_height="match_parent" />

</RelativeLayout> `

**Activity_main.xml:**

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"


    package="com.example.agronotizie13">

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




    <application
        android:allowBackup="true"
        android:icon="@mipmap/ic_launcher"
        android:label="@string/app_name"
        android:roundIcon="@mipmap/ic_launcher_round"
        android:supportsRtl="true"
        android:usesCleartextTraffic="true"
        android:theme="@style/AppTheme">
        <activity android:name=".MainActivity">
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />

                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
    </application>

</manifest>


  [1]: https://stackoverflow.com/questions/30637654/android-webview-gives-neterr-cache-miss-message
James
  • 25
  • 8

1 Answers1

0

My current configuration was blocking network loads which is preventing the WebView from loading web resources.

In my MainActivity.java:

webView.getSettings().setBlockNetworkLoads(true);

The setBlockNetworkLoads method determines whether the WebView should block all network loads. When the value is true, all network loads are blocked. So if we set this to true, WebView won't be able to load our URL, hence the net::ERR_CACHE_MISS error.

To solve this, we need to set setBlockNetworkLoads to false:

webView.getSettings().setBlockNetworkLoads(false);
James
  • 25
  • 8