java.lang.NoClassDefFoundError:android.media.projection.MediaProjectionManager

时间:2016-03-22 08:01:54

标签: android

MediaProjectionManager manager =
        (MediaProjectionManager) activity.getSystemService(MEDIA_PROJECTION_SERVICE);
    Intent intent = manager.createScreenCaptureIntent();
    activity.startActivityForResult(intent, CREATE_SCREEN_CAPTURE);

这是我的代码,我收到以下错误

03-22 07:52:02.271 14831-14831/? E/dalvikvm: Could not find class 'android.media.projection.MediaProjectionManager', referenced from method com.zennaxx.marshmallowscreenrecorder.CaptureHelper.fireScreenCaptureIntent
03-22 07:52:02.371 14831-14831/? E/AndroidRuntime: FATAL EXCEPTION: main
03-22 07:52:02.371 14831-14831/? E/AndroidRuntime: Process: com.zennaxx.marshmallowscreenrecorder, PID: 14831
03-22 07:52:02.371 14831-14831/? E/AndroidRuntime: java.lang.NoClassDefFoundError: android.media.projection.MediaProjectionManager
03-22 07:52:02.371 14831-14831/? E/AndroidRuntime:     at com.zennaxx.marshmallowscreenrecorder.CaptureHelper.fireScreenCaptureIntent(CaptureHelper.java:22)
03-22 07:52:02.371 14831-14831/? E/AndroidRuntime:     at com.zennaxx.marshmallowscreenrecorder.ScreenRecorderActivity.onLaunchClicked(ScreenRecorderActivity.java:136)
03-22 07:52:02.371 14831-14831/? E/AndroidRuntime:     at com.zennaxx.marshmallowscreenrecorder.ScreenRecorderActivity$$ViewBinder$6.doClick(ScreenRecorderActivity$$ViewBinder.java:80)
03-22 07:52:02.371 14831-14831/? E/AndroidRuntime:     at butterknife.internal.DebouncingOnClickListener.onClick(DebouncingOnClickListener.java:22)
03-22 07:52:02.371 14831-14831/? E/AndroidRuntime:     at android.view.View.performClick(View.java:4569)
03-22 07:52:02.371 14831-14831/? E/AndroidRuntime:     at android.view.View$PerformClick.run(View.java:18570)
03-22 07:52:02.371 14831-14831/? E/AndroidRuntime:     at android.os.Handler.handleCallback(Handler.java:733)
03-22 07:52:02.371 14831-14831/? E/AndroidRuntime:     at android.os.Handler.dispatchMessage(Handler.java:95)
03-22 07:52:02.371 14831-14831/? E/AndroidRuntime:     at android.os.Looper.loop(Looper.java:212)
03-22 07:52:02.371 14831-14831/? E/AndroidRuntime:     at android.app.ActivityThread.main(ActivityThread.java:5135)
03-22 07:52:02.371 14831-14831/? E/AndroidRuntime:     at java.lang.reflect.Method.invokeNative(Native Method)
03-22 07:52:02.371 14831-14831/? E/AndroidRuntime:     at java.lang.reflect.Method.invoke(Method.java:515)
03-22 07:52:02.371 14831-14831/? E/AndroidRuntime:     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:878)
03-22 07:52:02.371 14831-14831/? E/AndroidRuntime:     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:694)
03-22 07:52:02.371 14831-14831/? E/AndroidRuntime:     at dalvik.system.NativeStart.main(Native Method)

1 个答案:

答案 0 :(得分:3)

如果您在API级别太低的设备上启动应用程序,则此异常是典型的(即常见的编程错误)。该类需要API Level 21,因此您应该在build.gradle中将min API Level设置为21或执行一些异常处理/分支