WebView未显示URL

时间:2018-05-26 10:42:03

标签: java android webview

我来自这个主题:New activity not opening

应用程序现在可以正常运行,但用于显示课程的WebView无法正常工作。

// Argomento.java

import android.app.ProgressDialog;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.webkit.WebSettings;
import android.webkit.WebView;
import android.webkit.WebViewClient;

public class Argomento extends AppCompatActivity {

private ProgressDialog progDailog;

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_argomento);
    String nomeDispensa = getIntent().getStringExtra("dispensa");

    progDailog = ProgressDialog.show(this, "Loading","Please wait...", true);
    progDailog.setCancelable(false);

    WebView documentOpener = findViewById(R.id.documentOpener);
    WebSettings webSettings = documentOpener.getSettings();
    webSettings.setJavaScriptEnabled(true);
    webSettings.setLoadWithOverviewMode(true);
    webSettings.setUseWideViewPort(true);

    documentOpener.setWebViewClient(new WebViewClient(){

        @Override
        public boolean shouldOverrideUrlLoading(WebView view, String url) {
            progDailog.show();
            view.loadUrl(url);
            return true;
        }
        @Override
        public void onPageFinished(WebView view, final String url) {
            progDailog.dismiss();
        }
    });

    documentOpener.loadUrl(nomeDispensa);
}
}

// activity_argomento.xml

<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.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.fabio.myschoolsyllabus.Argomento">

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

</android.support.constraint.ConstraintLayout>

我认为我正确输入了所有代码,但网页没有显示,Android Studio会将此日志返回给我:

I/WebViewFactory: Loading com.android.chrome version 58.0.3029.125 (code 
303012512)
I/cr_LibraryLoader: Time to load native libraries: 2 ms (timestamps 8632- 
8634)
I/chromium: [INFO:library_loader_hooks.cc(140)] Chromium logging enabled: 
level = 0, default verbosity = 0
I/cr_LibraryLoader: Expected native library version number "58.0.3029.125", 
actual native library version number "58.0.3029.125"
W/cr_ChildProcLauncher: Create a new ChildConnectionAllocator with package 
name = com.android.chrome, inSandbox = true
I/cr_BrowserStartup: Initializing chromium process, singleProcess=false
D/: HostConnection::get() New Host Connection established 0x89833d80, tid 
7494
D/EGL_emulation: eglCreateContext: 0x98f1adc0: maj 2 min 0 rcv 2
D/EGL_emulation: eglMakeCurrent: 0x98f1adc0: ver 2 0 (tinfo 0x98b68e20)
W/ResourceType: For resource 0x7f0a0030, entry index(48) is beyond type 
entryCount(2)
Failure getting entry for 0x7f0a0030 (t=9 e=48) (error -75)
E/GooglePlayServicesUtil: The Google Play services resources were not found. 
Check your project configuration to ensure that the resources are included.
W/cr_media: Requires BLUETOOTH permission
I/cr_LibraryLoader: Using linker: 
org.chromium.base.library_loader.ModernLinker
I/zygote: Do partial code cache collection, code=30KB, data=43KB
I/zygote: After code cache collection, code=30KB, data=43KB
I/zygote: Increasing code cache capacity to 256KB
I/zygote: JIT allocated 71KB for compiled code of void 
android.widget.TextView.<init>(android.content.Context, 
android.util.AttributeSet, int, int)
Compiler allocated 4MB to compile void android.widget.TextView.<init> 
(android.content.Context, android.util.AttributeSet, int, int)
D/EGL_emulation: eglMakeCurrent: 0x98f18360: ver 2 0 (tinfo 0x98ba9890)
D/: HostConnection::get() New Host Connection established 0x86094dc0, tid 
7571
D/EGL_emulation: eglCreateContext: 0x8604b2c0: maj 2 min 0 rcv 2
D/EGL_emulation: eglMakeCurrent: 0x8604b2c0: ver 2 0 (tinfo 0x86095170)
I/VideoCapabilities: Unsupported profile 4 for video/mp4v-es
W/cr_MediaCodecUtil: HW encoder for video/avc is not available on this 
device.
W/cr_MediaCodecUtil: HW encoder for video/avc is not available on this 
device.
E/chromium: [ERROR:gl_surface_egl.cc(264)] eglChooseConfig failed with error 
EGL_SUCCESS
D/EGL_emulation: eglCreateContext: 0x8604bf80: maj 2 min 0 rcv 2
D/EGL_emulation: eglMakeCurrent: 0x8604bf80: ver 2 0 (tinfo 0x86095170)
W/zygote: Attempt to remove non-JNI local reference, dumping thread
D/EGL_emulation: eglMakeCurrent: 0x98f18360: ver 2 0 (tinfo 0x98ba9890)
D/EGL_emulation: eglMakeCurrent: 0x98f18360: ver 2 0 (tinfo 0x98ba9890)
I/Choreographer: Skipped 63 frames!  The application may be doing too much 
work on its main thread.
D/EGL_emulation: eglMakeCurrent: 0x98f18360: ver 2 0 (tinfo 0x98ba9890)
I/zygote: Do full code cache collection, code=121KB, data=80KB
After code cache collection, code=117KB, data=55KB
D/EGL_emulation: eglMakeCurrent: 0x98f18360: ver 2 0 (tinfo 0x98ba9890)
I/chatty: uid=10085(u0_a85) RenderThread identical 1 line
D/EGL_emulation: eglMakeCurrent: 0x98f18360: ver 2 0 (tinfo 0x98ba9890)
W/zygote: Attempt to remove non-JNI local reference, dumping thread
D/EGL_emulation: eglMakeCurrent: 0x98f18360: ver 2 0 (tinfo 0x98ba9890)
W/zygote: Attempt to remove non-JNI local reference, dumping thread

修改

我已经在AndroidManifest.xml中添加了Internet Permission。

为了测试WebView,用作&#34; nomeDispensa&#34;的值的URL是我可以选择的最简单的网页:&#34; www.google.it&#34;。

1 个答案:

答案 0 :(得分:0)

您必须使用完整的网址:

https://www.google.com

或类似的东西