无法使用webview查看网页

tjvv9vkg  于 2021-07-09  发布在  Java
关注(0)|答案(1)|浏览(337)


这是webview的xml文件

<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context="com.example.testing.WebViewExample">

    <WebView
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:id="@+id/webView"
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintLeft_toLeftOf="parent"
        app:layout_constraintRight_toRightOf="parent"
        app:layout_constraintTop_toTopOf="parent" />

</androidx.constraintlayout.widget.ConstraintLayout>

这段代码是针对webview.java的

public class MainActivity extends AppCompatActivity {
      @Override  
      protected void onCreate(Bundle savedInstanceState) {  
        super.onCreate(savedInstanceState);  
        setContentView(R.layout.activity_main);  
        WebView mywebview = (WebView) findViewById(R.id.webView);  

        mywebview.loadUrl("https://www.google.com/");  

    }  
}

但问题是我无法查看谷歌和它显示的网页不可用的错误
网页位于https://www.google.com/ 无法加载,因为:
网络::错误\u缓存\u未命中

kgsdhlau

kgsdhlau1#

您可能需要将internet权限添加到清单文件:

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

另一个引用:android webview中的loadurl()失败,出现net::err\u cache\u miss

相关问题