Reputation: 33
When I try to create an animation using the following code I get the following error:
The method loadAnimation(context,int) in the type AnimationUtils is not applicable for the arguments(MainActivity.PlaceholderFragment,int)
Animation textAnimation= AnimationUtils.loadAnimation(this,R.anim.text_animation);
I also get a null pointer exception. How do I fix this?
Upvotes: 1
Views: 4394
Reputation: 1
Try This
Animation rotateimage = AnimationUtils.loadAnimation(this,android.R.anim.fade_in);
Upvotes: 0
Reputation: 7881
i think this
is something which is not equal to Context
, try replacing below code.
Animation textAnimation= AnimationUtils.loadAnimation(getContext(),R.anim.text_animation);
EDIT: if you are using this code inside Fragment then call getActivity().getContext()
instead this
Upvotes: 4
Reputation: 4780
Looks like you are trying to call this function from inside the PlaceholderFragment that is declared inside MainActivity. loadAnimation expects a context in the first parameter. You can fix this problem by chNging the first argument from "this" to either getActivity() or to MainActivity.this
Upvotes: 1