【发布时间】:2020-12-24 22:22:53
【问题描述】:
我试图在打开MyProfileEdit 片段时向用户显示他们的个人资料图片。
我目前遇到空指针异常
java.lang.NullPointerException: Argument must not be null
at com.bumptech.glide.util.Preconditions.checkNotNull(Preconditions.java:29)
at com.bumptech.glide.util.Preconditions.checkNotNull(Preconditions.java:23)
at com.bumptech.glide.RequestBuilder.into(RequestBuilder.java:669)
at com.example.byfimvp.ui.MyProfileEditFragment.onCreateView(MyProfileEditFragment.kt:36)
当我尝试从 firebase 存储中获取用户图像时:
override fun onCreateView(
inflater: LayoutInflater, container: ViewGroup?,
savedInstanceState: Bundle?
): View? {
// Inflate the layout for this fragment
val currentUser = FirebaseAuth.getInstance().currentUser
if (currentUser != null) {
if (currentUser!!.photoUrl != null) {
Log.d("MyProfileEditFragment", "PHOTO URL: ${currentUser!!.photoUrl}")
Glide.with(this).load(currentUser.photoUrl).into(imv_my_profile_picture)
}
}
return inflater.inflate(R.layout.fragment_my_profile_edit, container, false)
}
我检查了日志,但 currentUser 和 photoUrl 都不为空
【问题讨论】:
-
很遗憾,
imv_my_profile_picture为空。 -
将您的代码切换到 onViewCreated() 方法。
标签: android firebase kotlin firebase-storage android-glide