当我尝试在我的Android Things webview中加载网页时,页面最初加载,然后使用指向IoT FrameworkPackageStubs的错误消息崩溃UI。
我在Dev Preview 5.1上使用Raspberry Pi,它支持Webview和OpenGL,但不知道为什么我的简单应用程序似乎崩溃了。它的代码如下
@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 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'
}
最后是我在拨打电话时收到的错误消息。
--------- 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并输入搜索时,它会崩溃并显示相同的消息。
感谢您的帮助。
答案 0 :(得分:1)
您可能遇到与here相同的问题。
在Android中加载链接时,默认情况下系统会尝试启动应用程序来处理URL,在本例中为浏览器。但Android事件默认情况下不包含浏览器,因此无法处理URL和崩溃。
您可以通过在加载任何网址之前在应用中设置WebViewClient来覆盖此默认行为并在应用的WebView中加载网址:
WebView myWebView = (WebView) findViewById(R.id.webview);
myWebView.setWebViewClient(new WebViewClient());
记录在案here。
答案 1 :(得分:0)
如果您有一个Web视图以及一个进度条,则代码位于以下位置:
WebView myWebView = (WebView) findViewById(R.id.webView3);
progressDialog = new ProgressDialog(YOUR_ACTIVITY.this);
progressDialog.setCancelable(true);
progressDialog.setMessage("Please wait....");
progressDialog.show();
myWebView.setWebViewClient(new WebViewClient() { // setting Progress Bar
@Override
public boolean shouldOverrideUrlLoading(WebView view, String url) {
view.loadUrl(url);
Log.d(TAG, "LOADING");
return true;
}
@Override
public void onPageFinished(WebView view, String url) {
if (progressDialog.isShowing()) {
progressDialog.dismiss();
}
}
});
myWebView.setInitialScale(1);
myWebView.getSettings().setLoadWithOverviewMode(true);
myWebView.getSettings().setUseWideViewPort(true);
myWebView.getSettings().setJavaScriptEnabled(true);myWebView.loadUrl("https://www.google.com");
myWebView.getSettings().setSupportZoom(true);
myWebView.getSettings().setBuiltInZoomControls(true);
myWebView.getSettings().setDisplayZoomControls(false);