Rondev
Rondev

Reputation: 928

Loading image with Glide causes exception

I'm trying to get a drawable from a url with Glide but it keeps failing.

I'm using Glide version 4.12.0 which is the latest: implementation 'com.github.bumptech.glide:glide:4.12.0'

I've already tried using RequestListener but it kept failing, therefore I am looking for an alternative.

imageUrl = https://firebasestorage.googleapis.com/v0/b/podsync-dev.appspot.com/o/commentImages%2FAB5D35BB-E925-486A-A280-81358636D8EB?alt=media&token=daf6f99c-323a-4cfc-af97-3354d9f8e4e9

Here's my code:

comment.imageURL?.takeIf { loadImage }?.let { imageUrl ->
    Glide.with(context).load(comment.imageURL).into(object : CustomTarget<Drawable>() {
        override fun onLoadFailed(errorDrawable: Drawable?) {
            // code
        }
        override fun onResourceReady(resource: Drawable,
                                     transition: Transition<in Drawable>?) {

            // code
        }
        override fun onLoadCleared(placeholder: Drawable?) {
            // code
        }
    })
}

Here's the exception I'm getting:

java.lang.NoClassDefFoundError: Failed resolution of: Lcom/galdahan/podsync/Models/Comment$Companion$transform$5$1;
        at com.galdahan.podsync.Models.Comment$Companion.transform(Comment.kt:71)
        at com.galdahan.podsync.Models.Comment$Companion.transform$default(Comment.kt:47)
        at com.galdahan.podsync.FIREBASE_API.Post_CommnentsApi$observeComments$1.onDataChange(Post_CommnentsApi.kt:75)
        at com.google.firebase.database.Query$1.onDataChange(com.google.firebase:firebase-database@@19.2.0:179)
        at com.google.firebase.database.core.ValueEventRegistration.fireEvent(com.google.firebase:firebase-database@@19.2.0:75)
        at com.google.firebase.database.core.view.DataEvent.fire(com.google.firebase:firebase-database@@19.2.0:63)
        at com.google.firebase.database.core.view.EventRaiser$1.run(com.google.firebase:firebase-database@@19.2.0:55)
        at android.os.Handler.handleCallback(Handler.java:938)
        at android.os.Handler.dispatchMessage(Handler.java:99)
        at android.os.Looper.loop(Looper.java:223)
        at android.app.ActivityThread.main(ActivityThread.java:7656)
        at java.lang.reflect.Method.invoke(Native Method)
        at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:592)
        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:947)
     Caused by: java.lang.ClassNotFoundException: Didn't find class "com.galdahan.podsync.Models.Comment$Companion$transform$5$1" on path: DexPathList[[dex file "/data/data/com.galdahan.podsync/code_cache/.overlay/base.apk/classes6.dex", zip file "/data/app/~~u26Hv32StBK7WzdCxOOa-A==/com.galdahan.podsync-gxbX5HkcbxEI2A_Cnrev2A==/base.apk"],nativeLibraryDirectories=[/data/app/~~u26Hv32StBK7WzdCxOOa-A==/com.galdahan.podsync-gxbX5HkcbxEI2A_Cnrev2A==/lib/x86_64, /system/lib64, /system_ext/lib64]]
        at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:207)
        at java.lang.ClassLoader.loadClass(ClassLoader.java:379)
        at java.lang.ClassLoader.loadClass(ClassLoader.java:312)
        at com.galdahan.podsync.Models.Comment$Companion.transform(Comment.kt:71) 
        at com.galdahan.podsync.Models.Comment$Companion.transform$default(Comment.kt:47) 
        at com.galdahan.podsync.FIREBASE_API.Post_CommnentsApi$observeComments$1.onDataChange(Post_CommnentsApi.kt:75) 
        at com.google.firebase.database.Query$1.onDataChange(com.google.firebase:firebase-database@@19.2.0:179) 
        at com.google.firebase.database.core.ValueEventRegistration.fireEvent(com.google.firebase:firebase-database@@19.2.0:75) 
        at com.google.firebase.database.core.view.DataEvent.fire(com.google.firebase:firebase-database@@19.2.0:63) 
        at com.google.firebase.database.core.view.EventRaiser$1.run(com.google.firebase:firebase-database@@19.2.0:55) 
        at android.os.Handler.handleCallback(Handler.java:938) 
        at android.os.Handler.dispatchMessage(Handler.java:99) 
        at android.os.Looper.loop(Looper.java:223) 
        at android.app.ActivityThread.main(ActivityThread.java:7656) 
        at java.lang.reflect.Method.invoke(Native Method) 
        at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:592) 
        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:947) 

Upvotes: 0

Views: 778

Answers (1)

KE Keronei
KE Keronei

Reputation: 330

From the stacktrace, here are some few things that can be observed.

  • You are loading your data from firebase.
  • You have some form of implementation to map the data into models in podsync/Models/ when the firebase notifies you of changes.

Here's what you can do to single out your problem:

  • Comment out your code(glide implementation) to load the image
  • Comment out your mappings of objects from firebase to your models
  • Log your data from firebase to be sure of the structure/format that they are being loaded in.

At this point, your app should not be crashing. Proceed;

  • Carefully examine the Comment object from firebase and establish where the differences come from with your model(datatypes, number of children/properties, e.t.c) of comment or whichever model you are using to map it.

If you are listening to data changes inside onDataChange, you can use a try/catch to get the value from the snapshot and log it before conversion(as I had mentioned earlier).

Once you are sure of the fields in the expected object, update your model accordingly, then access the imageUrl property and pass it over to glide.

In summary, glide is not the cause of this crash, instead, it's how your data is being mapped to your local models.

Upvotes: 1

Related Questions