2

My Android app was first intended for Android 2.2 onwards so I used

player.getSettings().setPluginState(WebSettings.PluginState.ON);

for the WebView object.

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);
}

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?

EDIT: This error only appears on the 2.1 emulator.

bassicplays
  • 328
  • 1
  • 7
  • 21

1 Answers1

7

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.

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:

  1. Check which Android version the device is running, and only call PluginState when the device is running API-version >= 8.

  2. In your catch()-statement, catch NoClassDefFoundError instead of Exception.

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.

Reinier
  • 3,836
  • 1
  • 27
  • 28