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

Problem with Code Challenge: Part 3 Animating the Crystal Ball

I'm having trouble with this part of the challenge, I've referenced past threads (https://teamtreehouse.com/forum/problem-with-code-challenge-animating-the-crystal-ball)

The solution did not help me. This is my current code, it keeps telling me I'm wrong. I don't know what to do. Everything I've read up says this is right. Help!

Part 3 states: Continuing with animateFrog(), add an if statement to see if jumpAnimation is currently running, but don't do anything inside the curly braces yet. Remember that the condition to test goes inside parenthesis after the 'if' keyword. Use the 'isRunning()' method of the jumpAnimation variable.

My Code:

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

Nothing happens, still says: Compilation Error! Remember the syntax for an if statement: if (condition) { // code }

Don't know what the hell I'm doing wrong... I'm stuck.

1 Answer

Hmm... your code looks correct. My guess is that you wrote the right code, but you just have forgot a curly brace. Here is your code that I tried. It passed part 3 of the challenge. You can use it as a reference.

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

Ty this really helped........ I didn't notice that a simple error like a curly brace had such an effect.