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

Code Challenge: Animating the Crystal Ball

Hi,

I have been doing good so far in the tutorials, however I am stuck here.

The question is as follows :

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.

My answer is as follows :

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);
}
ImageView frogImage = (ImageView) findViewById(R.id.frog);

} public void animateFrog() {frogImage}

Please help ;)

3 Answers

Hey Adnan,

You are pretty close, but reading the directions again may help. The following is how I went about the code challenge.

1. Define a method called animateFrog()

Code:

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

    ImageView frogImage = (ImageView) findViewById(R.id.frog);

  public void animateFrog(){

  }
}

As you can see, all I added was a method called animateFrog()

2. Next it says: "and put the existing line of code that declares the 'frogImage' variable inside the curly braces of the new method."

So I take the existing line of code that declares the frogImage and I just paste it into my newly created method.

Code:

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

  }
}

3. Finally it states: "Make the method public, return nothing (void), and have no parameters."

Well... how convenient. When I defined my method in the first step, I made it public, I made it return void (nothing), and I gave it no parameters.

We're all done and it passes the challenge.

Keep coding!

Hey,

Just launched the app 2 days ago. But prior to that, I would like to say thanks for your patience, support and guidance. Doing this has been my boyhood dreams and I am excited to share this journey with the people here.

Thanks :)

It worked Thank You Sir :)