Welcome to the Treehouse Community
Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.
Looking to learn something new?
Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.
Start your free trialadnanalvee2
6,862 PointsAnswer doesn't have the animation effect.
Did everything as instructed in the video. The crystal ball animation is running but the answer is still the same. No fade in effect. Here is my code according the video. (```java
public class MainActivity extends Activity {
private CrystalBall mCrystalBall = new CrystalBall();
private TextView mAnswerLabel;
private Button mGetAnswerButton;
private ImageView mCrystalBallImage;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
// Assign the Views from the layout file
mAnswerLabel = (TextView) findViewById(R.id.textView1);
mGetAnswerButton = (Button) findViewById(R.id.button1);
mCrystalBallImage = (ImageView) findViewById(R.id.imageView1);
mGetAnswerButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
String answer = mCrystalBall.getAnAnswer();
// Update the label with our dynamic answer
mAnswerLabel.setText(answer);
animateCrystalBall();
animateAnswer();
}
});
}
private void animateCrystalBall() {
mCrystalBallImage.setImageResource(R.drawable.ball_animation);
AnimationDrawable ballAnimation = (AnimationDrawable) mCrystalBallImage.getDrawable();
if (ballAnimation.isRunning()) {
ballAnimation.stop();
}
ballAnimation.start();
}
private void animateAnswer() {
AlphaAnimation fadeInAnimation = new AlphaAnimation(0, 1);
fadeInAnimation.setDuration(1500);
fadeInAnimation.setFillAfter(true);
mAnswerLabel.setAnimation(fadeInAnimation);
}
6 Answers
Andre Kettschau
20,054 PointsI had the same problem - solved this by using
mAnswerLabel.startAnimation(fadeInAnimation);
instead of
mAnswerLabel.setAnimation(fadeInAnimation);
cbcbcb
16,560 PointsYou're using both the animateAnswer( ) and animateCrystalBall() methods as if they are static. So go back through the video and keep up the learning man. Try harder.
Joseph Greene
Courses Plus Student 7,638 PointsI've found that if I get too far off it is good to download the source code and compare it to what I have, And remember that the methods you're working with here aren't static as Christopher has already said above.
cbcbcb
16,560 Points@akshayshivpuri
Question - Could you explain Joseph Greene , why static methods are causing the problem as I didn't get it?
Answer - A static method doesn't require an instance of the class that it is declared in to be used. If you don't include "static " in the method's signature then the method will require a "calling object" when you want to use it. You often use the class name that the static method is declared in in the same syntax that you would use for a non-static method. Just substitute the object with the class name. I'm not good at explaining things. I would suggest you spend a short bit of time outside of this website and read a chapter on static and non-static method in Java.
Akshay Shivpuri
2,917 PointsCould you explain Joseph Greene/christopherbasinger , why static methods are causing the problem as I didn't get it.
Thanks in advance.
Akshay Shivpuri
2,917 PointsThanks christopherbasinger ! I got it.
adnanalvee2
6,862 Pointsadnanalvee2
6,862 PointsThanks man that helped.
It would have been impossible for me if you didn't help.
Looks like you are Java Guru!!