0

使用 WebView 处理应用程序:

在布局文件中:

 <WebView  xmlns:android="http://schemas.android.com/apk/res/android"
        android:id="@+id/webview"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
    />

在代码中:

mVideo = (WebView) findViewById(R.id.webview); mVideo.loadUrl(mDeviceHost + ":8080/stream/webrtc");

但是当我在设备上运行时:

java.lang.RuntimeException: Unable to start activity ComponentInfo{tprlab.com.pitanq/com.tprlab.pitanq.DashboardActivity}: android.view.InflateException: Binary XML file line #0: Binary XML file line #0: Error inflating class android.webkit.WebView
                                                                       at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2724)
                                                                       at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2785)
                                                                       at android.app.ActivityThread.-wrap12(ActivityThread.java)
                                                                       at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1532)
                                                                       at android.os.Handler.dispatchMessage(Handler.java:102)
                                                                       at android.os.Looper.loop(Looper.java:163)
                                                                       at android.app.ActivityThread.main(ActivityThread.java:6342)
                                                                       at java.lang.reflect.Method.invoke(Native Method)
                                                                       at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:880)
                                                                       at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:770)
                                                                    Caused by: android.view.InflateException: Binary XML file line #0: Binary XML file line #0: Error inflating class android.webkit.WebView
                                                                    Caused by: android.view.InflateException: Binary XML file line #0: Error inflating class android.webkit.WebView
                                                                    Caused by: java.lang.reflect.InvocationTargetException
                                                                       at java.lang.reflect.Constructor.newInstance0(Native Method)
                                                                       at java.lang.reflect.Constructor.newInstance(Constructor.java:430)
                                                                       at android.view.LayoutInflater.createView(LayoutInflater.java:652)
                                                                       at com.android.internal.policy.PhoneLayoutInflater.onCreateView(PhoneLayoutInflater.java:58)
                                                                       at android.view.LayoutInflater.onCreateView(LayoutInflater.java:742)
                                                                       at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:810)
                                                                       at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:752)
                                                                       at android.view.LayoutInflater.rInflate(LayoutInflater.java:883)
                                                                       at android.view.LayoutInflater.rInflateChildren(LayoutInflater.java:846)
                                                                       at android.view.LayoutInflater.rInflate(LayoutInflater.java:886)
                                                                       at android.view.LayoutInflater.rInflateChildren(LayoutInflater.java:846)
                                                                       at android.view.LayoutInflater.inflate(LayoutInflater.java:522)
                                                                       at android.view.LayoutInflater.inflate(LayoutInflater.java:430)
                                                                       at android.view.LayoutInflater.inflate(LayoutInflater.java:377)
                                                                       at android.support.v7.app.AppCompatDelegateImplV9.setContentView(AppCompatDelegateImplV9.java:287)
                                                                       at android.support.v7.app.AppCompatActivity.setContentView(AppCompatActivity.java:139)
                                                                       at com.tprlab.android.BaseActivity.onCreate(BaseActivity.java:55)
                                                                       at com.tprlab.pitanq.DashboardActivity.onCreate(DashboardActivity.java:133)
                                                                       at android.app.Activity.performCreate(Activity.java:6847)
                                                                       at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1119)
                                                                       at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2677)
                                                                       at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2785)
                                                                       at android.app.ActivityThread.-wrap12(ActivityThread.java)
                                                                       at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1532)
                                                                       at android.os.Handler.dispatchMessage(Handler.java:102)
                                                                       at android.os.Looper.loop(Looper.java:163)
                                                                       at android.app.ActivityThread.main(ActivityThread.java:6342)
                                                                       at java.lang.reflect.Method.invoke(Native Method)
                                                                       at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:880)
                                                                       at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:770)
                                                                    Caused by: java.lang.NullPointerException: Attempt to invoke virtual method 'boolean java.lang.String.equals(java.lang.Object)' on a null object reference
                                                                       at android.app.ResourcesManager.appendLibAssetForMainAssetPath(ResourcesManager.java:889)
                                                                       at android.webkit.WebViewDelegate.addWebViewAssetPath(WebViewDelegate.java:205)
                                                                       at yH.a(PG:19)
                                                                       at com.android.webview.chromium.WebViewChromium.<init>(PG:14)
                                                                       at com.android.webview.chromium.WebViewChromiumFactoryProvider.createWebView(PG:158)
                                                                       at android.webkit.WebView.ensureProviderCreated(WebView.java:2326)
                                                                       at android.webkit.WebView.setOverScrollMode(WebView.java:2385)
07-11 12:38:13.983 24794-24794/tprlab.com.pitanq E/AndroidRuntime:     at android.view.View.<init>(View.java:4007)
                                                                       at android.view.View.<init>(View.java:4126)
                                                                       at android.view.ViewGroup.<init>(ViewGroup.java:578)
                                                                       at android.widget.AbsoluteLayout.<init>(AbsoluteLayout.java:55)
                                                                       at android.webkit.WebView.<init>(WebView.java:627)
                                                                       at android.webkit.WebView.<init>(WebView.java:572)
                                                                       at android.webkit.WebView.<init>(WebView.java:555)
                                                                       at android.webkit.WebView.<init>(WebView.java:542)

任何想法如何解决这个问题?

PS。设备上的 Android 版本:7.0 NRD90M(sdk 版本 24) 构建选项:min sdk 版本 - 24 目标 - 26。(那是关键吗?)

4

0 回答 0