I can not go online due to ERR_CACHE_MISS

0

You see, I want to make a program that takes me to a web page (www.marca.com for the example).

For that, I have this XML code:

<?xml version="1.0" encoding="utf-8"?>
<WebView
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/webkit"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    />

And this Java code:

package com.example.pcx.cliente;

import android.app.Activity;
import android.os.Bundle;
import android.webkit.WebView;

public class MainActivity extends Activity{
    @Override
    protected void onCreate(Bundle savedInstanceState){
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        WebView browser=findViewById(R.id.webkit);
        browser.setWebViewClient(new MiControl());
        String cad="<html><body><a href='http://www.marca.com'>Visitar Marca</a></body></html>";
        browser.loadData(cad,"text/html","UTF-8");
    }
}

And here the code MiControl.java:

package com.example.pcx.cliente;


import android.webkit.WebView;
import android.webkit.WebViewClient;

public class MiControl extends WebViewClient{
    @Override
    public boolean shouldOverrideUrlLoading(WebView browser, String url){
            browser.loadUrl(url);
            return true;
        }
}

If I omit the part of the call to the class MyControl.java, it works in an expected way, but when even this class, I see myself with this:

What have you done wrong?

    
asked by Miguel Alparez 01.02.2018 в 21:58
source

1 answer

1

You have to give permission to your application to access the Internet.

This is achieved by opening the file:

  

AndroidManifest.xml

and adding the following line:

<uses-permission android:name="android.permission.INTERNET"></uses-permission>
    
answered by 02.02.2018 / 09:11
source