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 trial
Ihsan Ahmed
2,670 PointsBuild Simple Android App Code Chanllenge
I have got compilation error when I check the work so I do not know what I have to do to fix it I need help please.
Question -------
Inside the if statement, add a line to stop the animation if it is running, using the 'stop()' method of the jumpAnimation variable. Then add a line below the check to start the animation using the 'start()' method of the jumpAnimation variable.
Question -------
code ------
package com.example;
import android.app.Activity; import android.os.Bundle; import android.view.View; import android.widget.ImageView; import android.graphics.drawable.AnimationDrawable;
public class MainActivity extends Activity {
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
}
public void animateFrog(){ ImageView frogImage = (ImageView) findViewById(R.id.frog); AnimationDrawable jumpAnimation = (AnimationDrawable) frogImage.getDrawable();
if (jumpAnimation.isRunning ()){
jumpAnimation.stop();
animation.start();
}
} } code-----
4 Answers
Andrew Molloy
37,259 PointsThe animation variable is "jumpAnimation", for your start method you called it "animation".
Ihsan Ahmed
2,670 PointsThanks I got it.
Rajesh Mule
2,125 Pointsif (jumpAnimation.isRunning ()){ jumpAnimation.stop(); jumpAnimation.start(); }
Ihsan Ahmed
2,670 PointsHi I have sorted aout that problem long time ago, thanks anyway.