当我尝试将上传的图片加载到我主页的导航标题中时,该应用程序会出错。
错误:
FATAL EXCEPTION: main Process: com.example.cqaai.tutorpal, PID: 23741 java.lang.IllegalArgumentException: You must pass in a non null View
at com.bumptech.glide.GenericRequestBuilder.into(GenericRequestBuilder.java:685)
at com.bumptech.glide.DrawableRequestBuilder.into(DrawableRequestBuilder.java:457)
at com.example.cqaai.tutorpal.activity.HomeActivity$3.onDataChange(HomeActivity.java:199)
at com.google.android.gms.internal.zzbmz.zza(Unknown Source)
at com.google.android.gms.internal.zzbnz.zzYj(Unknown Source)
at com.google.android.gms.internal.zzboc$1.run(Unknown Source)
at android.os.Handler.handleCallback(Handler.java:751)
at android.os.Handler.dispatchMessage(Handler.java:95)
at android.os.Looper.loop(Looper.java:159)
at android.app.ActivityThread.main(ActivityThread.java:6097)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:865)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:755)
最后一个if语句是错误的原因:
private void getUserInfo() {
mTuteeDatabase.addValueEventListener(new ValueEventListener() {
@Override
public void onDataChange(DataSnapshot dataSnapshot) {
if(dataSnapshot.exists() && dataSnapshot.getChildrenCount()>0){
Map<String, Object> map = (Map<String, Object>) dataSnapshot.getValue();
if(map.get("FullName")!=null){
mFullName = map.get("FullName").toString();
txtFullName.setText(mFullName);
}
if(map.get("UserName")!=null) {
mUserName = map.get("UserName").toString();
txtUserName.setText("@" + mUserName);
}
if(map.get("profileImageUrl")!=null){
mProfileImageUrl = map.get("profileImageUrl").toString();
Glide.with(getApplication()).load(mProfileImageUrl).into(mProfileImage);
}
}
}
@Override
public void onCancelled(DatabaseError databaseError) {
}
});
}
我在gist.github
中添加了其他链接。其中包含相关的xml
和数据库结构。如果我以错误的方式提出问题,请原谅我。
complete codings: HomeActivity.java
, activity_home
, etc here
答案 0 :(得分:0)
您的mProfileImage
是null
。
变化:
mProfileImage = (ImageView) findViewById(R.id.profileImage);
致:
mProfileImage = (ImageView) findViewById(R.id.imageProfile);
答案 1 :(得分:0)
试试这个:
final NavigationView navigationView = (NavigationView) findViewById(R.id.nav_view);
final View header = navigationView.getHeaderView(0);
final ImageView mProfileImage = (ImageView) header.findViewById(R.id.image);