class ContentResolver 或其超 classes 中没有虚方法 loadThumbnail()
No virtual method loadThumbnail() in class ContentResolver or its super classes
当我使用public @NonNull Bitmap loadThumbnail(@NonNull Uri uri, @NonNull Size size,@Nullable CancellationSignal signal)
方法时,
它总是显示这个错误
2019-12-24 16:16:10.661 30299-30299/com.shaheen.filemanager E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.shaheen.filemanager, PID: 30299
java.lang.NoSuchMethodError: No virtual method loadThumbnail(Landroid/net/Uri;Landroid/util/Size;Landroid/os/CancellationSignal;)Landroid/graphics/Bitmap; in class Landroid/content/ContentResolver; or its super classes (declaration of 'android.content.ContentResolver' appears in /system/framework/framework.jar)
at com.shaheen.filemanager.activities.FileSelectActivity.onCreate(FileSelectActivity.kt:38)
at android.app.Activity.performCreate(Activity.java:7036)
at android.app.Activity.performCreate(Activity.java:7027)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1215)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2731)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2856)
at android.app.ActivityThread.-wrap11(Unknown Source:0)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1589)
at android.os.Handler.dispatchMessage(Handler.java:106)
at android.os.Looper.loop(Looper.java:164)
at android.app.ActivityThread.main(ActivityThread.java:6501)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:438)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:807)
有没有其他方法可以解决这个错误?
我的代码如下所示:
val bitmap = applicationContext.contentResolver.loadThumbnail(uri,Size(5,5),null)
thumbnail_image_view.setImageBitmap(bitmap)
screenshot_image_view.setImageBitmap(bitmap)
您是否尝试传递 activity 或片段的上下文而不是应用程序上下文?
方法 loadThumbnail()
仅在 Android 10.0 的 API 级别 29 中添加,因此它在较低版本中不起作用。
但是,您可以使用像 picasso 这样的图像加载器库或使用 uri
.
的 glide
当我使用public @NonNull Bitmap loadThumbnail(@NonNull Uri uri, @NonNull Size size,@Nullable CancellationSignal signal)
方法时,
它总是显示这个错误
2019-12-24 16:16:10.661 30299-30299/com.shaheen.filemanager E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.shaheen.filemanager, PID: 30299
java.lang.NoSuchMethodError: No virtual method loadThumbnail(Landroid/net/Uri;Landroid/util/Size;Landroid/os/CancellationSignal;)Landroid/graphics/Bitmap; in class Landroid/content/ContentResolver; or its super classes (declaration of 'android.content.ContentResolver' appears in /system/framework/framework.jar)
at com.shaheen.filemanager.activities.FileSelectActivity.onCreate(FileSelectActivity.kt:38)
at android.app.Activity.performCreate(Activity.java:7036)
at android.app.Activity.performCreate(Activity.java:7027)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1215)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2731)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2856)
at android.app.ActivityThread.-wrap11(Unknown Source:0)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1589)
at android.os.Handler.dispatchMessage(Handler.java:106)
at android.os.Looper.loop(Looper.java:164)
at android.app.ActivityThread.main(ActivityThread.java:6501)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:438)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:807)
有没有其他方法可以解决这个错误?
我的代码如下所示:
val bitmap = applicationContext.contentResolver.loadThumbnail(uri,Size(5,5),null)
thumbnail_image_view.setImageBitmap(bitmap)
screenshot_image_view.setImageBitmap(bitmap)
您是否尝试传递 activity 或片段的上下文而不是应用程序上下文?
方法 loadThumbnail()
仅在 Android 10.0 的 API 级别 29 中添加,因此它在较低版本中不起作用。
但是,您可以使用像 picasso 这样的图像加载器库或使用 uri
.