Hot questions for Using Glide in android activity

Top 10 Java Open Source / Glide / android activity


I am trying to load images using the Glide Library from firebase. The image url is correct(Checked it using Logcat) . I am using glide in an activity and not a fragment. I am getting this error 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).

Here is my code:

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;

protected void onCreate(Bundle savedInstanceState) {

    auth = FirebaseAuth.getInstance();
    databaseReference = FirebaseDatabase.getInstance().getReference();
    final FirebaseUser user = auth.getCurrentUser();
    nameTextView = (TextView) findViewById(;
    bioTextView = (TextView) findViewById(;
    logOut = (Button) findViewById(;
    editProfile = (Button) findViewById(;
    slidr = Slidr.attach(this);
    profilepic = (CircleImageView) findViewById(;
    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() {
        public void onDataChange(DataSnapshot dataSnapshot) {
            name2 = (String) dataSnapshot.child("name").getValue();
            bio2 = (String) dataSnapshot.child("bio").getValue();

            String gender = (String) dataSnapshot.child("gender").getValue();
            String email = (String) dataSnapshot.child("email").getValue();

            Log.d("TAG", "Name: " + name2);
            Log.d("TAG", "Email: " + email);
            Log.d("TAG", "Gender: " + gender);
            Log.d("TAG", "Profile Pic URI = " + imageUri);

            String imageUrl = (String) dataSnapshot.child("profilePic").getValue();


        public void onCancelled(DatabaseError databaseError) {}


    logOut.setOnClickListener(new View.OnClickListener() {
        public void onClick(View v) {
            SharedPreferences settings = getSharedPreferences(SignIn.PREFS_NAME, 0);
            SharedPreferences.Editor editor = settings.edit();
            editor.putBoolean("hasLoggedIn", false);
            boolean hasLoggedIn = settings.getBoolean("hasLoggedIn", false);
            Intent intent = new Intent(ProfileActivity.this, SignIn.class);

    editProfile.setOnClickListener(new View.OnClickListener() {
        public void onClick(View v) {
            Intent intent = new Intent(ProfileActivity.this, EditProfile.class);

    Log.d("TAG" , "NAME OUTSIDE " +name2);


If im not using using fragments why am I getting this error.

Also how will I solve this error. Please help me


From the log, it is possible that your context is null. Try using activity directly like this