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

Android Build a Simple Android App (retired 2014) Pretty Little Things Animating the Crystal Ball

Siddharth Saravanan
Siddharth Saravanan
1,208 Points

Stuck on code challenge! Please help I watched the video a billion times and I still cant get it!

I am stuck on task 2 of 4 in the "Animating the Crystal Ball" code challenge. Here is the code I thought would work for this code challenge(2 of 4).

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();
}
jumpAnimation.start();

}

If anyone can help please help!

2 Answers

Tommy Gebru
Tommy Gebru
30,164 Points

Here try this out,

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();
    }
}