setPluginState和setPluginsEnabled [英] setPluginState and setPluginsEnabled
问题描述
我的Android应用程序最初是针对Android 2.2的起,所以我用
My Android app was first intended for Android 2.2 onwards so I used
player.getSettings().setPluginState(WebSettings.PluginState.ON);
有关web视图对象。
现在,我已经决定要打开我的应用程序到Android 2.1的用户,我改变了我的code这样:
Now that I've decided to open my app to Android 2.1 users, I changed my code to this:
try {
player.getSettings().setPluginState(WebSettings.PluginState.ON);
} catch (Exception e) {
player.getSettings().setPluginsEnabled(true);
}
有了这个,应用程序强制关闭,我得到我的logcat这个错误:
With this, the app force closes and I get this error on my logcat:
Uncaught handler: thread main exiting due to uncaught exception
java.lang.NoClassDefFoundError: android.webkit.WebSettings$PluginState
at com.dokgu.joindota.WatchVOD.onCreate(WatchVOD.java:34)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2459)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2512)
at android.app.ActivityThread.access$2200(ActivityThread.java:119)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1863)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:123)
at android.app.ActivityThread.main(ActivityThread.java:4363)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:521)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:860)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:618)
at dalvik.system.NativeStart.main(Native Method)
这个错误任何帮助吗?
Any help with this error?
编辑:
该错误只出现在2.1模拟器。
This error only appears on the 2.1 emulator.
推荐答案
一个有点晚了 - 我敢肯定你已经理解了它现在 - 但这个错误是由类 PluginState <所致/ code>不是适用于Android版本&LT; 2.2(API 8)。请参见上PluginState android的文档。
A bit late - I'm sure you've figured it out by now - but the error is caused by the class PluginState
not being available on Android versions < 2.2 (API 8). See the android docs on PluginState.
为什么你不能用抓住这个原因尝试{}赶上(例外五){}
是因为的NoClassDefFoundError
不是 例外
- 这是一个 错误
。而错误
和例外
是的 的Throwable
他们是不一样的,因此你不能赶上一个错误
与例外
,反之亦然。
The reason why you can't catch this with try {} catch (Exception e) {}
is because the NoClassDefFoundError
is not an Exception
- it's an Error
. While Error
and Exception
are both children of Throwable
they are not the same, hence you cannot catch an Error
with an Exception
and vice versa.
要解决这个问题,你可以采取以下任一方式:
To solve this you can take either of the following approaches:
-
检查设备运行的Android版本,并只调用设备运行API的版本时
PluginState
> = 8。
在你的赶上()
语句来,抓的NoClassDefFoundError
而不是异常
。
In your catch()
-statement, catch NoClassDefFoundError
instead of Exception
.
此外,Eclipse将最有可能表现出皮棉警告提 PluginState
级仅在API可用8+。您可以隐藏/加忽略此警告 @燮pressLint(NewApi)
您上面的方法就行了。
Also, Eclipse will most likely show a Lint-warning mentioning the PluginState
-class is only available on API 8+. You can hide/ignore this warning by adding @SuppressLint("NewApi")
to the line above your method.
这篇关于setPluginState和setPluginsEnabled的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!