亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

無法使用 Glide 庫加載圖像

無法使用 Glide 庫加載圖像

呼啦一陣風 2023-03-23 15:19:36
我正在嘗試使用來自 firebase 的 Glide 庫加載圖像。圖片 url 正確(使用 Logcat 檢查)。我在活動中使用滑行而不是片段。我收到這個錯誤 java.lang.NullPointerException: You cannot start a load on a not yet attached View or a Fragment where getActivity() returns null (which usually occurs when getActivity() is called before the Fragment is attached or after the Fragment is destroyed).這是我的代碼:public class ProfileActivity extends AppCompatActivity {FirebaseAuth auth;DatabaseReference databaseReference;TextView nameTextView , bioTextView;String name2 , bio2 , uidString;Uri imageUri , FilePathUri;Button logOut , editProfile;private SlidrInterface slidr;CircleImageView profilepic;StorageReference storageReference;String Storage_Path = "ProfilePictures/" , downloadUrl;Context context;@Overrideprotected void onCreate(Bundle savedInstanceState) {    super.onCreate(savedInstanceState);    setContentView(R.layout.activity_profile);    auth = FirebaseAuth.getInstance();    databaseReference = FirebaseDatabase.getInstance().getReference();    final FirebaseUser user = auth.getCurrentUser();    nameTextView = (TextView) findViewById(R.id.name);    bioTextView = (TextView) findViewById(R.id.bio);    logOut = (Button) findViewById(R.id.logout2);    editProfile = (Button) findViewById(R.id.editprofile);    slidr = Slidr.attach(this);    profilepic = (CircleImageView) findViewById(R.id.profilepic);    storageReference = FirebaseStorage.getInstance().getReference();    Intent intent = getIntent();    Bundle uid = intent.getExtras();    uidString = uid.getString("UID");    Log.d("UID OF USER" , "UID OF USER = "+uidString);    final Context finalContext = context;    databaseReference.child("users").child(uidString).addValueEventListener(new ValueEventListener() {        }如果我不使用片段,為什么會出現此錯誤。另外我將如何解決這個錯誤。請幫我
查看完整描述

2 回答

?
紅糖糍粑

TA貢獻1815條經驗 獲得超6個贊

從日志來看,你的可能context是空的。嘗試像這樣直接使用活動

GlideApp.with(ProfileActivity.this).load(imageUrl).into(profilepic);


查看完整回答
反對 回復 2023-03-23
?
ibeautiful

TA貢獻1993條經驗 獲得超6個贊

嘗試這個 :

GlideApp.with(profilepic.getContext()).load(imageUrl).into(profilepic);


查看完整回答
反對 回復 2023-03-23
  • 2 回答
  • 0 關注
  • 206 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號