即使没有错误,Webview也不会显示

时间:2020-07-16 17:35:45

标签: java android html logcat

我的应用有一个webview。不仅是约束布局和网站的Web视图,而且还具有设置为Internet的权限。为什么我的应用程序上仍然出现空白页? 我的代码: 清单

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

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

    <application
        android:allowBackup="true"
        android:icon="@mipmap/ic_launcher"
        android:label="@string/app_name"
        android:roundIcon="@mipmap/ic_launcher_round"
        android:supportsRtl="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>

我的代码

package com.-----.samudrafootwearstore;

import androidx.appcompat.app.AppCompatActivity;

import android.os.Bundle;
import android.webkit.WebView;
import android.webkit.WebViewClient;

public class MainActivity extends AppCompatActivity {

    WebView wb;

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

        wb = findViewById(R.id.samudrafootwearpage);
        wb.setWebViewClient(new WebViewClient());
        wb.loadUrl("www.google.com");
    }
}

和布局:

<?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=".MainActivity">

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

</androidx.constraintlayout.widget.ConstraintLayout>

logcat:

2020-07-16 23:05:02.661 29736-29743/? E/art: Failed sending reply to debugger: Broken pipe
2020-07-16 23:05:03.053 29736-29783/? E/libEGL: validate_display:300 error 3008 (EGL_BAD_DISPLAY)

有人可以帮我这个忙吗? 谢谢

1 个答案:

答案 0 :(得分:1)

它可以代替yes来进行wb.loadUrl("www.google.com");