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

Define methods and declare variables

hello everyone it's Alexander i am having a lot of trouble with this question. Define a method called 'animateFrog' and place 'FrogImage variable inside the curlybraces of the new method. make the method public,return nothing void and have no paremeters. Please help would deeply appreciate it!!!

10 Answers

Randy Perez
Randy Perez
5,668 Points

I think that you might be writing the method outside the main class. Because other than that your code looks great, you have to start after the close curly bracket if the onCreate method, Anyways let me share the whole 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);
                        }

}
Randy Perez
Randy Perez
5,668 Points

Hello Alexander, I think I can lend you a hand here. My only doubt is the type of the FrogImage variable, other than that your method should look like the code below, feel free to ask e further questions.

<code> public void animateFrog(){ public String FrogImage; } </code>

Hey Randy thankyou for your input it is much appreciated! That being said i tried the code you suggested and it didnt solve the equation. I'm getting kind of frustrated but i'm still trying to hang in. Do you have any other suggestions let me know buddy thanks!!!

Randy Perez
Randy Perez
5,668 Points

Ok, given that I took the time to check the code challenge by myself and yes you only have to declare the method as I did before but there is an exiting line of code that you to move inside the method in order to declare the FrogImage variable. At the end it should look like this.

  public void animateFrog(){
    ImageView frogImage = (ImageView) findViewById(R.id.frog);
  }

Hey Randy its Alex I dont know whats going on. I pretty much tried everything including the line of code you've provided. Another thing i noticed is that when the question is given the declaration " imageview frogImage = (ImageView) findViewById(R.id.frog); is at the top as prexisting code. now i know im new but i believe it isnt good to repeat the same line of code. Did you pass the code challenge? maybe iim wrong please let me know thanks!!!

Randy Perez
Randy Perez
5,668 Points

Yes, I did pass it. Can you post your answer? so I can take a look at it and help you out

This exactly how i answered the question public void animateFrog() { ImageView frogImage = (ImageView) findViewById(R.id.frog; } PS Did you start on line 19? Thanks man you truely are a friend of mind for taking the time

This exactly how i answered the question public void animateFrog() { ImageView frogImage = (ImageView) findViewById(R.id.frog; } PS Did you start on line 19? Thanks man you truely are a friend of mind for taking the time

Wooooow my only little mistake was not placing the curly brace after the semicolen. I thought the one already given was enough! Thanks bro if you ever need anything just let me know your a champion !!

Randy Perez
Randy Perez
5,668 Points

I see you are starting the journey of the android development,so I am. It will be nice to have someone to share tips and experiences along the way so anything you can hit me up at randyjp125@gmail.com.