在Kotlin中使用?.let {}块的NoClassDefFoundError

时间:2018-03-03 04:23:51

标签: android kotlin android-glide kotlin-null-safety

我无法弄清楚为什么会出现以下错误:

  

E / UncaughtException:java.lang.NoClassDefFoundError:解析失败   的:   LCOM / somecompany / someapp /普通/滑行/ GlideWrapper $ loadCircularProfileImg $ 1 $ 1;                                                                                    在   com.somecompany.someapp.common.glide.GlideWrapper.loadCircularProfileImg(GlideWrapper.kt:31)                                                                                    在   com.somecompany.someapp.main.MainActivity.showSideBarProfPhoto(MainActivity.kt:179)                                                                                    在   com.somecompany.someapp.main.MainActivity.onCreate(MainActivity.kt:115)                                                                                    在android.app.Activity.performCreate(Activity.java:6955)                                                                                    在   android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1126)                                                                                    在   android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2927)                                                                                    在   android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3045)                                                                                    在android.app.ActivityThread.-wrap14(ActivityThread.java)                                                                                    在   android.app.ActivityThread $ H.handleMessage(ActivityThread.java:1642)                                                                                    在android.os.Handler.dispatchMessage(Handler.java:102)                                                                                    在android.os.Looper.loop(Looper.java:154)                                                                                    在android.app.ActivityThread.main(ActivityThread.java:6776)                                                                                    at java.lang.reflect.Method.invoke(Native Method)                                                                                    在   com.android.internal.os.ZygoteInit $ MethodAndArgsCaller.run(ZygoteInit.java:1520)                                                                                    在com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1410)

代码:

fun loadCircularProfileImg(ctx: Context, user: User?, targetImageView: ImageView) {

        user?.let {
            // With let getting a NoClassDefFoundError error 

            GlideApp.with(ctx)
                    .asBitmap()
                    .load(FirebaseStorage.getInstance().reference.child(it.profImgUrl))
                    .into(object : BitmapImageViewTarget(targetImageView) {
                        override fun setResource(resource: Bitmap?) {
                            // Will add code here
                        }
                    })
        }
    }

但不是:

fun loadCircularProfileImg(ctx: Context, user: User?, targetImageView: ImageView) {

    if (user != null) {   // With this the code works

        GlideApp.with(ctx)
                .asBitmap()
                .load(FirebaseStorage.getInstance().reference.child(user.profImgUrl))
                .into(object : BitmapImageViewTarget(targetImageView) {
                    override fun setResource(resource: Bitmap?) {
                        // Will add code here
                    }
                })
    }
}

1 个答案:

答案 0 :(得分:1)

当你调用loadCircularProfileImg时,用户类定义的时候我调用的方法相同,并且没有得到如下所示的任何错误......

        loadCircularProfileImg(this,User(),imageview)

我在上面的代码中使用,没有收到任何错误。