Webview loadurl 崩溃 [英] Webview loadurl crashing

查看:26
本文介绍了Webview loadurl 崩溃的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

尝试在我的 Android Things 网页视图中加载 url 时,页面最初加载,然后 UI 崩溃,并显示一条指向 IoT FrameworkPackageStubs 的错误消息.

When trying to load a url in my Android Things webview the page initially loads, then crashes the UI with an error message pointing towards the IoT FrameworkPackageStubs.

我在 Dev Preview 5.1 上使用 Raspberry Pi,它支持 Webviews 和 OpenGL,但不知道为什么我的非常简单的应用程序似乎崩溃了.其代码如下

I am using a Raspberry Pi on Dev Preview 5.1 which supports Webviews and OpenGL but have no idea why my very simple application seems to be crashing. The code for it is as follows

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

    WebView webView = (WebView) findViewById(R.id.webView);
    if(webView != null)
    webView.loadUrl("https://www.facebook.com");
}

这是我的清单文件

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

    <uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE"/>
    <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
    <uses-permission android:name="android.permission.INTERNET"/>
    <uses-permission android:name="android.permission.BLUETOOTH"/>
    <uses-permission android:name="android.permission.BLUETOOTH_ADMIN"/>

    <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">
        <uses-library android:name="com.google.android.things" android:required="false"/>
        <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>

和我的 Gradle 依赖

and my Gradle depdencies

dependencies {
    compile fileTree(dir: 'libs', include: ['*.jar'])
    androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', {
        exclude group: 'com.android.support', module: 'support-annotations'
    })
    compile 'com.android.support:appcompat-v7:26.+'
    compile 'com.android.support.constraint:constraint-layout:1.0.2'
    testCompile 'junit:junit:4.12'

    provided 'com.google.android.things:androidthings:0.5.1-devpreview'
}

最后是我在拨打电话时收到的错误消息.

And finally my error message I'm receiving when making the calls.

    --------- beginning of crash
08-31 20:30:33.458 10146-10146/com.google.android.iot.frameworkpackagestubs E/AndroidRuntime: FATAL EXCEPTION: main
                                                                                              Process: com.google.android.iot.frameworkpackagestubs, PID: 10146
                                                                                              java.lang.RuntimeException: Unable to instantiate activity ComponentInfo{com.google.android.iot.frameworkpackagestubs/com.google.android.iot.frameworkpackagestubs.Stubs$BrowserStub}: java.lang.ClassNotFoundException: Didn't find class "com.google.android.iot.frameworkpackagestubs.Stubs$BrowserStub" on path: DexPathList[[zip file "/system/app/IoTFrameworkPackageStubs/IoTFrameworkPackageStubs.apk"],nativeLibraryDirectories=[/system/app/IoTFrameworkPackageStubs/lib/arm, /system/lib, /system/vendor/lib, /system/lib, /system/vendor/lib]]
                                                                                                  at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2718)
                                                                                                  at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2892)
                                                                                                  at android.app.ActivityThread.-wrap11(Unknown Source:0)
                                                                                                  at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1593)
                                                                                                  at android.os.Handler.dispatchMessage(Handler.java:105)
                                                                                                  at android.os.Looper.loop(Looper.java:164)
                                                                                                  at android.app.ActivityThread.main(ActivityThread.java:6541)
                                                                                                  at java.lang.reflect.Method.invoke(Native Method)
                                                                                                  at com.android.internal.os.Zygote$MethodAndArgsCaller.run(Zygote.java:240)
                                                                                                  at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:767)
                                                                                               Caused by: java.lang.ClassNotFoundException: Didn't find class "com.google.android.iot.frameworkpackagestubs.Stubs$BrowserStub" on path: DexPathList[[zip file "/system/app/IoTFrameworkPackageStubs/IoTFrameworkPackageStubs.apk"],nativeLibraryDirectories=[/system/app/IoTFrameworkPackageStubs/lib/arm, /system/lib, /system/vendor/lib, /system/lib, /system/vendor/lib]]
                                                                                                  at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:93)
                                                                                                  at java.lang.ClassLoader.loadClass(ClassLoader.java:379)
                                                                                                  at java.lang.ClassLoader.loadClass(ClassLoader.java:312)
                                                                                                  at android.app.Instrumentation.newActivity(Instrumentation.java:1173)
                                                                                                  at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2708)
                                                                                                  at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2892) 
                                                                                                  at android.app.ActivityThread.-wrap11(Unknown Source:0) 
                                                                                                  at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1593) 
                                                                                                  at android.os.Handler.dispatchMessage(Handler.java:105) 
                                                                                                  at android.os.Looper.loop(Looper.java:164) 
                                                                                                  at android.app.ActivityThread.main(ActivityThread.java:6541) 
                                                                                                  at java.lang.reflect.Method.invoke(Native Method) 
                                                                                                  at com.android.internal.os.Zygote$MethodAndArgsCaller.run(Zygote.java:240) 
                                                                                                  at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:767) 

我承认有些网站确实有效,但是当我访问 https://www.google.com 时并输入搜索,它会以相同的消息崩溃.

I will admit some websites do work, but when I go to https://www.google.com and type in a search it crashes with the same message.

感谢您的帮助.

推荐答案

您可能遇到与 此处.

当链接在 Android 中加载时,默认情况下系统会尝试启动一个应用程序来处理 URL,在这种情况下是浏览器.但是 Android Things 默认不包含浏览器,因此无法处理 URL 并崩溃.

When links are loaded in Android, by default the system will try to launch an application to handle the URL, in this case a browser. However Android Things does not include a browser by default, so it fails to handle the URL and crashes.

通过在加载任何 URL 之前在应用中设置 WebViewClient,您可以覆盖此默认行为并在应用的 WebView 中加载 URL:

You can override this default behavior and have the URLs load in your app's WebView, by setting the WebViewClient in your app before loading any URLs:

WebView myWebView = (WebView) findViewById(R.id.webview);
myWebView.setWebViewClient(new WebViewClient());

此处记录了这一点.

这篇关于Webview loadurl 崩溃的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆