1

I have created a fragment in which an animation for rotation is there.

    Animation rotation = AnimationUtils.loadAnimation(getContext(), R.anim.rotate);

When loading the fragment for the first time the animation is finely loaded.

But when coming back to the activity from another activity using intent, it loading the activity fine, loading the fragment fine but giving

    Attempt to invoke virtual method 'android.content.res.Resources android.content.Context.getResources()' on a null object reference

pointing

   Animation rotation = AnimationUtils.loadAnimation(getContext(), R.anim.rotate);

Please help. Thanks in advance.

Sourav Roy
  • 323
  • 4
  • 12

1 Answers1

1

Change

   Animation rotation = AnimationUtils.loadAnimation(getContext(), R.anim.rotate);

to

    Animation rotation = AnimationUtils.loadAnimation(getActivity(), R.anim.rotate);
Ragesh Ramesh
  • 3,470
  • 2
  • 14
  • 20