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

Keith Cox
PLUS
Keith Cox
Courses Plus Student 1,291 Points

Challenge 2 Crystal ball Pretty Little Things

Android Development Pretty Little Things exercise: 2 of 4

I keep getting an error code at

./com/example/MainActivity.java:19: cannot find symbol symbol : variable drawable location: class com.example.R frogImage.setImageResource(R.drawable.frog); ^ 1 error

Please give a brief description along with answer so that I may grasp the process better. Thank YOu

Inside animateFrog(), declare an AnimationDrawable variable named 'jumpAnimation'. Initialize it using the 'getDrawable()' method of the 'frogImage' variable. Don’t forget to cast it to an AnimationDrawable with β€˜(AnimationDrawable)’!

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); frogImage.setImageResource(R.drawable.frog); AnimationDrawable jumpAnimation = (AnimationDrawable) frogImage.getDrawable(); }

}

1 Answer

Hello Keith!

In Task 2 of this Challenge you are declaring a variable named jumpAnimation:

AnimationDrawable jumpAnimation;

Then you initialize it using the getDrawable() method of the frogImage variable:

AnimationDrawable jumpAnimation = frogImage.getDrawable();

In the last step you should cast it to an AnimationDrawable type:

AnimationDrawable jumpAnimation = (AnimationDrawable) frogImage.getDrawable();

The final code should be:

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