title: You cannot start a load on a not yet attached View or a Fragment where getActivity()
body: <p>The application crashes when I switch from the profile fragmnett to another fragment. I couldn't figure out how to solve it.I don't know what to do because I'm new at android. I'm waiting for your help</p>
  
  <p>debug console:</p>
  
  <pre><code>E/AndroidRuntime: FATAL EXCEPTION: main
  Process: com.bg.askandtalk, PID: 21676
  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).
      at com.bumptech.glide.util.Preconditions.checkNotNull(Preconditions.java:31)
      at com.bumptech.glide.Glide.getRetriever(Glide.java:675)
      at com.bumptech.glide.Glide.with(Glide.java:707)
      at com.bg.askandtalk.Fragments.ProfileFragment$1.onDataChange(ProfileFragment.java:83)
      at com.google.android.gms.internal.firebase_database.zzfc.zza(Unknown Source:13)
      at com.google.android.gms.internal.firebase_database.zzgx.zzdr(Unknown Source:2)
      at com.google.android.gms.internal.firebase_database.zzhd.run(Unknown Source:71)
      at android.os.Handler.handleCallback(Handler.java:873)
      at android.os.Handler.dispatchMessage(Handler.java:99)
      at android.os.Looper.loop(Looper.java:193)
      at android.app.ActivityThread.main(ActivityThread.java:6669)
      at java.lang.reflect.Method.invoke(Native Method)
      at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:493)
      at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:858)
  </code></pre>
  
  <p>my profile fragment</p>
  
  <pre><code>public class ProfileFragment extends Fragment {
  
  CircleImageView image_profile;
  TextView username;
  
  DatabaseReference reference;
  FirebaseUser fuser;
  
  StorageReference storageReference;
  private static final int IMAGE_REQUEST = 1;
  private Uri imageUri;
  private StorageTask uploadTask;
  private ImageButton postButton;
  
  
  @Override
  public View onCreateView(LayoutInflater inflater, ViewGroup container,
                           Bundle savedInstanceState) {
      View view = inflater.inflate(R.layout.fragment_profile, container, false);
  
      image_profile = view.findViewById(R.id.profile_image);
      username = view.findViewById(R.id.username);
      postButton = (ImageButton) view.findViewById(R.id.post_button);
  
      storageReference = FirebaseStorage.getInstance().getReference("uploads");
  
      fuser = FirebaseAuth.getInstance().getCurrentUser();
      reference = FirebaseDatabase.getInstance().getReference("Users").child(fuser.getUid());
  
      reference.addValueEventListener(new ValueEventListener() {
          @Override
          public void onDataChange(@NonNull DataSnapshot dataSnapshot) {
              User user = dataSnapshot.getValue(User.class);
              username.setText(user.getUsername());
              if (user.getImageURL().equals("default")){
                  image_profile.setImageResource(R.mipmap.ic_launcher);
              } else {
                  Glide.with(getContext()).load(user.getImageURL()).into(image_profile);
              }
          }
  </code></pre>