You call the animate();
method on the ImageView
class itself and not the instance. This will only work when the method is declared as a static
method.
From the question and the very straight forward error message, I can see that you're not familiar with the static keyword. So I'll explain it to you...
A static method can be very usefull in some cases and knowing what it is can help you in the future.
An example would be the decode();
method from the class Long
. It decodes a String
into a Long
(how it does it is unimportant). The method isn't in the String
class, because encapsulation is important in OOP and if you had 20 different decode();
methods for Int, Long, Double... that would create a big chaos in the String
class. That's why we put it in the Long class itself in the first place and not in the String
class.
If the method wasn't a static you would need to write it like that:
String string = "123";
Long number = new Long();
number.decode(string);
With the static it looks like this:
String string = "123";
Long number = new Long();
number = Long.decode(string);
As you can see, using static
was very usefull back then, because you are able to see that you use the decode method from Long
and not from Int
, Double
or anything like that. If you had 100 text rows between Long number = new Long();
and number.decode(string);
, it wouldn't be very easy to find out from which class the method was and with that which result you'll get.
But this isn't a problem anymore. With a compiler like eclipse, you can see from which class a method comes from, without the static
keyword. The only point why java classes still use it is:
It works and if they changed it, many programs wouldn't work anymore.
Now to your question. You treat the animate();
method like a static
method, which it isn't and that makes sense. You only want to animate the specific instance of a class, in your case bart. That means(like Stultuske already said) you need to replace the class with an instance of the class in front of .animate()
, in this case bart.
You need to replace this:
ImageView bart = (ImageView) findViewById(R.id.bart);
ImageView.animate().alpha(0).setDuration(2000);
with this:
ImageView bart = (ImageView) findViewById(R.id.bart);
bart.animate().alpha(0).setDuration(2000);
You create an instance of ImageView
called bart
and after that, you want to animate the created instance with [instance].animate()...
not the class itself.