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


Animating the Crystal Ball Challenge. Pulling my hair out for the last hour over this challenge! I feel like all of the sudden the tasks went from fairly simple to really hard. I watched the video over and over and I have no idea what I'm doing with this.

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 {

public void onCreate(Bundle savedInstanceState) {

  public void animateFrog(){
    ImageView frogImage = (ImageView) findViewById(R.id.frog);
    AnimationDrawable frogAnimation = (AnimationDrawable) frogImage.getDrawable();

5 Answers

The way it is right now, the program doesn't know what resource contains the animation information. You need the ID of the XML file that contains your animation information inside the parenthesis in the line frogImage.setImageResource();. Assuming the XML file inside of your drawables folder is named ball_animation.xml, it would be done like this.


Thanks for your help...I still don't understand what I'm doing with this unfortunately so I gave up on that tract for the time being, I think maybe team treehouse isn't for absolute beginners, I will be back after I get some beginner training elsewhere.

Don't give up, just slowly read the code and try to understand what you're trying to do. I know, I know, easier said than done and I must admit, that at first I quite didn't grasp the whole thing, but after doing the quiz and rereading my code I somewhat got it, or at least I think I did.

  • you have an imageView " frogImage" which you're trying to animate
  • you want to wrap it around the animation method "animateFrog", which basically says, "hey, I'm going to animate your image!"
  • but for the image to actually be animated, you need to call upon the 'AnimationDrawable subclass', you create one right there and then and u call it "frogAnimation", and then you just simply attach it to your imageView(frogImage) with "getDrawable()"

-If you were making a pizza, the imageView(frogImage) would be your pizza, the "animateFrog()" would be the oven, and the AnimationDrawable(frogAnimation) will be the action of turning the oven on

Now, that's how I understood it, please someone correct if wrong?

PS: don't forget to take a break every once in a while, especially when you're learning something totally new. ;)

The instructions never said to put


Here is what the code when finished with the challenge:

    public void animateFrog() {
        ImageView frogImage = (ImageView) findViewById(R.id.frog);
    AnimationDrawable jumpAnimation = (AnimationDrawable) frogImage.getDrawable();
    if (jumpAnimation.isRunning()) {

Don't give up. I'm new to programming. Just analyze what has been done after each video. I'm not understand everything but I'm still making progress. However, I would agree that this isn't the best place for beginners to learn programming.