Shaheen Ahamed S
Shaheen Ahamed S

Reputation: 176

No virtual method loadThumbnail() in class ContentResolver or its super classes

When I use public @NonNull Bitmap loadThumbnail(@NonNull Uri uri, @NonNull Size size,@Nullable CancellationSignal signal) method ,

it is always showing this error

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)

Is there is any other way to solve this error ?

My code looks like this :

val bitmap = applicationContext.contentResolver.loadThumbnail(uri,Size(5,5),null)
thumbnail_image_view.setImageBitmap(bitmap)
screenshot_image_view.setImageBitmap(bitmap)

Upvotes: 1

Views: 1948

Answers (2)

Olu Udeh
Olu Udeh

Reputation: 1061

The method loadThumbnail() was only added in API level 29 that Android 10.0 so it won't work in lower versions. However, you can use image loader libraries like picasso or glide with the uri.

Upvotes: 1

Talha Ahmed
Talha Ahmed

Reputation: 66

Have you tried passing the context of activity or fragment instead of application context ?

Upvotes: 0

Related Questions