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

Shelby Kessel
PLUS
Shelby Kessel
Courses Plus Student 1,482 Points

Animating the Crystal Ball

Hello I was wondering if anyone could help me out, I'm stuck on the first task of the "Animating the Crystal Ball" challenge and I've re-watched the video I don't know how many times now but I'm pretty sure I keep looking over something but anyways this is the task "Define a method called 'animateFrog()' and put the existing line of code that declares the 'frogImage' variable inside the curly braces of the new method. Make the method public, return nothing (void), and have no parameters." this is what I have 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();
    AnimationDrawable frogAnimation = (AnimationDrawable) frogImage.getDrawable();
}

} I figure I'm missing something but I cannot figure it out, I don't know if this will help anyone but I keep getting a Compilation Error when I try to complete the task so I thought the code might have been in the wrong area so I have tried it outside of the main activity class just to see and have gotten the same error so if anyone could help me, I would very much appreciate it :).

8 Answers

Ben Jakuben
STAFF
Ben Jakuben
Treehouse Teacher

This is a scenario where a full-fledged IDE like Eclipse makes this easy to solve. :smile: If you get stuck on code challenges like this in the future, copy and paste your code into Eclipse and you might be able to get some helpful information.

But this is a simple case of a missing curly brace. You need to end your onCreate method before starting your animateFrog method, which means you just need to add a right curly brace } before starting your animateFrog method. I don't want to just paste in the solution, so hopefully that spells it out for you!

Shelby Kessel
PLUS
Shelby Kessel
Courses Plus Student 1,482 Points

Thank You very much Ben, I can't believe I didn't see that before haha, I really appreciate your help! :)

Ben Jakuben
STAFF
Ben Jakuben
Treehouse Teacher

Glad to help! Sometimes fresh eyes is all it takes!

I too am stuck on this problem and cannot seem to find a solution. This is what I have down:

@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(); AnimationDrawable frogAnimation = (AnimationDrawable) frogImage.getDrawable(); }

}

If anyone could help that would be great. Thanks

Ben Jakuben
STAFF
Ben Jakuben
Treehouse Teacher

Hi @Nigel,

Delete the 2nd line in your animateFrog() method (frogImage.setImageResource();) and you should be good to go. :smile:

Need help with this as well, can't seem to complete

 @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
    }
  public void animateFrog() {
    ImageView frogImage = (ImageView) findViewById(R.id.frogImage);
    frogImage.setImageResource();
    AnimationDrawable frogAnimation = (AnimationDrawable) frogImage.getDrawable();

}
Ben Jakuben
Ben Jakuben
Treehouse Teacher

Hi Matthew,

The same hint above looks like it will apply here. You don't need that setImageResource() call in there. :)

Thanks Ben

It works great. Thank you!

I'm so lost, I keep getting recheck work whenever I submit this no matter how many changes I put it through. I have watched the video 8 times making sure to pause and let it sink in. I've even read through the problems of previous people and can't find out the answer.Here's what I have thus far.

@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();
    AnimationDrawable frogAnimation = frogImage.getDrawable();
}
Ben Jakuben
Ben Jakuben
Treehouse Teacher

Hi Keiley,

Looks like copying and pasting code from in here is causing problems! Disregard the other code you see in this post as none of these solutions will work for you.

With your code, you have two problems:

  1. You don't need that 'setImageResource()' call in there.
  2. Compare the name of your AnimationDrawable variable with the name that is specified in the instructions: "Inside animateFrog(), declare an AnimationDrawable variable named 'jumpAnimation'."

[pic](C:\Users\Joey\Desktop\test.png "Test")

[test](C:\Users\Joey\Desktop\test.png "Title")