java.lang.IllegalArgumentException:我的 logcat 中的目标不能为空
java.lang.IllegalArgumentException: Target must not be null at my logcat
当我将图像 url 传递给 Picasso 时,它显示错误 "Target must not be null"。当我使用毕加索从 url 获取图像时,它显示错误。
我的logcat
java.lang.IllegalArgumentException: Target must not be null.
at com.squareup.picasso.RequestCreator.into(RequestCreator.java:682)
at com.squareup.picasso.RequestCreator.into(RequestCreator.java:665)
at com.example.instagramclone.fragment.ProfileFragment$userInfo.onDataChange(ProfileFragment.kt:191)
at com.google.firebase.database.core.ValueEventRegistration.fireEvent(com.google.firebase:firebase-database@@19.3.0:75)
at com.google.firebase.database.core.view.DataEvent.fire(com.google.firebase:firebase-database@@19.3.0:63)
at com.google.firebase.database.core.view.EventRaiser.run(com.google.firebase:firebase-database@@19.3.0:55)
at android.os.Handler.handleCallback(Handler.java:789)
at android.os.Handler.dispatchMessage(Handler.java:98)
at android.os.Looper.loop(Looper.java:169)
at android.app.ActivityThread.main(ActivityThread.java:6595)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.Zygote$MethodAndArgsCaller.run(Zygote.java:240)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:767)
我的xml
<com.mikhaellopez.circularimageview.CircularImageView
android:id="@+id/pro_image_profile_frag"
android:layout_width="161dp"
android:layout_height="90dp"
android:src="@drawable/profile1">
</com.mikhaellopez.circularimageview.CircularImageView>
我的activity
Picasso.get().load(user!!.getImage()).placeholder(R.drawable.profile1).into(pro_image_profile_frag)
view?.profile_fragment_username?.text = user!!.getFullname()
view?.full_name_profile_frag?.text = user!!.getUsername()
view?.bio_profile_frag?.text = user!!.getBio()
当您调用 into()
函数时,变量 pro_image_profile_frag
为空。请在调用into()
函数前检查是否已经初始化。它应该是这样的:
val pro_image_profile_frag = findViewById(R.id.view_id)
当我将图像 url 传递给 Picasso 时,它显示错误 "Target must not be null"。当我使用毕加索从 url 获取图像时,它显示错误。
我的logcat
java.lang.IllegalArgumentException: Target must not be null.
at com.squareup.picasso.RequestCreator.into(RequestCreator.java:682)
at com.squareup.picasso.RequestCreator.into(RequestCreator.java:665)
at com.example.instagramclone.fragment.ProfileFragment$userInfo.onDataChange(ProfileFragment.kt:191)
at com.google.firebase.database.core.ValueEventRegistration.fireEvent(com.google.firebase:firebase-database@@19.3.0:75)
at com.google.firebase.database.core.view.DataEvent.fire(com.google.firebase:firebase-database@@19.3.0:63)
at com.google.firebase.database.core.view.EventRaiser.run(com.google.firebase:firebase-database@@19.3.0:55)
at android.os.Handler.handleCallback(Handler.java:789)
at android.os.Handler.dispatchMessage(Handler.java:98)
at android.os.Looper.loop(Looper.java:169)
at android.app.ActivityThread.main(ActivityThread.java:6595)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.Zygote$MethodAndArgsCaller.run(Zygote.java:240)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:767)
我的xml
<com.mikhaellopez.circularimageview.CircularImageView
android:id="@+id/pro_image_profile_frag"
android:layout_width="161dp"
android:layout_height="90dp"
android:src="@drawable/profile1">
</com.mikhaellopez.circularimageview.CircularImageView>
我的activity
Picasso.get().load(user!!.getImage()).placeholder(R.drawable.profile1).into(pro_image_profile_frag)
view?.profile_fragment_username?.text = user!!.getFullname()
view?.full_name_profile_frag?.text = user!!.getUsername()
view?.bio_profile_frag?.text = user!!.getBio()
当您调用 into()
函数时,变量 pro_image_profile_frag
为空。请在调用into()
函数前检查是否已经初始化。它应该是这样的:
val pro_image_profile_frag = findViewById(R.id.view_id)