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 trialAlexander Moise
1,410 PointsDefine 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
5,668 PointsI 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
5,668 PointsHello 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>
Alexander Moise
1,410 PointsHey 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
5,668 PointsOk, 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);
}
Alexander Moise
1,410 PointsHey 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
5,668 PointsYes, I did pass it. Can you post your answer? so I can take a look at it and help you out
Alexander Moise
1,410 PointsThis 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
Alexander Moise
1,410 PointsThis 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
Alexander Moise
1,410 PointsWooooow 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
5,668 PointsI 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.