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 Self-Destructing Message Android App Adding Users Using Parse.com Error Messages with Dialogs

J Smillie
J Smillie
39,714 Points

Can't get through this challenge despite having the correct code in android studio

Challenge Task 2 of 5

The mNumberField variable is set from the layout in the onCreate() method, which is omitted below. In the makeGuess() method, set mUserInput using the text value from mNumberField. (Don't worry about making sure it's a number--that's handled by the GuessEngine class.)

I have the correct code in my own app on android studio but can't pass this challenge. I think it's confusing because some code is omitted.

Can anyone help with the answer they got for this?

J Smillie
J Smillie
39,714 Points

I have this so far:

      import android.app.Activity;
      import android.app.AlertDialog;
      import android.app.AlertDialog.Builder;
      import android.widget.EditText;

public class GuessNumberActivity extends Activity {

protected EditText mNumberField;
protected String mUserInput;

/*
 * onCreate() and other code has been omitted for brevity!
 */

public void makeGuess() {
    // Set mUserInput here!       
   String mNumberField = mUserInput.getText().toString();

    // Check to see if the user's number is correct
    boolean isCorrect = GuessEngine.testGuess(mUserInput);

}

}

2 Answers

In the makeGuess() method, set mUserInput using the text value from mNumberField.

String mNumberField = mUserInput.getText().toString();

it says set user input using the text value from mNumberField...not the other way round. So it suppose to go along these lines

  mUserInput = mNumberField.getText().toString();
J Smillie
J Smillie
39,714 Points

thanks again gloria!

You are welcome Jonathan.