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: Animating the Crystal Ball

Hi, I'm having a bit of trouble with part 3 of the Code Challenge: Animating the Crystal Ball. The question is copied in quotation marks below, and my code follows. I'm not sure what the error is here? Thanks!

"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."

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

        };

};

3 Answers

I'm pretty sure your code has a few too many semicolons.

I believe that challenge went something like this:

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

  }

That should be all you need. Simply remove the two semicolons you have. Let me know if you need anymore help.

Hey, I tried doing exactly what you did , and i even tried copy and pasting it in, but it still says "Compilation Error! Remember the syntax for an if statement: if (condition) { // code }" , Please help, Im stuck, i dont know what im doing wrong.

Can you post your entire code that you're trying? Even if you are "copying and pasting it in". We might be able to spot something simple that is off. =)

I'm having the same problem as them

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 jumpAnimationn = (AnimationDrawable) frogImage.getDrawable();
 if (jumpAnimation.isRunning()){
}

} }

I'm not sure if the spacing you are adding is throwing off the challenge system.

This code works... so hopefully you can compare your code with it.

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

  }
}

I'm having trouble as well, I have my code exactly like this:

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.

I was having this problem at first also; it turned out to be missing one closing curly bracket "}"

If you take a look at Ernest's code above, there should be three closing curly brackets:

1- to close the if (jumpAnimation.isRunning()) statement 2- to close the animateFrog method 3- to close the MainActivity class