Android Kotlin:无法使用 glide 将 firebase 存储图像加载到片段中
Android Kotlin: Cannot load a firebase storage image into fragment using glide
我试图在打开 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
都不为空
因为视图本身还没有初始化。
override fun onCreateView(
inflater: LayoutInflater, container: ViewGroup?,
savedInstanceState: Bundle?
): View? {
// Inflate the layout for this fragment
//view is yet to be initialixed
return inflater.inflate(R.layout.fragment_my_profile_edit, container, false)
}
你应该在 onViewCreated()
中加载滑行图像
例如
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
super.onViewCreated(view, savedInstanceState)
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)
}
}
}
我试图在打开 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
都不为空
因为视图本身还没有初始化。
override fun onCreateView(
inflater: LayoutInflater, container: ViewGroup?,
savedInstanceState: Bundle?
): View? {
// Inflate the layout for this fragment
//view is yet to be initialixed
return inflater.inflate(R.layout.fragment_my_profile_edit, container, false)
}
你应该在 onViewCreated()
中加载滑行图像例如
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
super.onViewCreated(view, savedInstanceState)
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)
}
}
}