Ngatesh
Ngatesh

Reputation: 33

The method loadAnimation in the type AnimationUtils is not applicable for the arguments

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

Answers (3)

Dhaval Mehta
Dhaval Mehta

Reputation: 1

Try This

Animation rotateimage = AnimationUtils.loadAnimation(this,android.R.anim.fade_in);

Upvotes: 0

dharmendra
dharmendra

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

Ahmed Ghonim
Ahmed Ghonim

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

Related Questions