我正在嘗試使用來自 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);

ibeautiful
TA貢獻1993條經驗 獲得超6個贊
嘗試這個 :
GlideApp.with(profilepic.getContext()).load(imageUrl).into(profilepic);
添加回答
舉報
0/150
提交
取消