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

Android - Self-Destruct Messaging App Project - Error Messages with Dialogue Code Challenge 2 of 5

Hiya Everyone!

In Code Challenge 2 of 5, we are asked to store the text from mUserInput from numberField. Sorry if I couldn't copy and paste the whole challenge question but the popup covered the question.

Have I understood the question?

Can anyone give me some insight with what I am doing wrong here

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

public class GuessNumberActivity extends Activity {

    protected String mUserInput;
    protected EditText mNumberField;

    // onCreate() and other code has been omitted

    public void makeGuess() {
        // Set mUserInput here!
        mUserInput = (EditText)findViewById(R.id.numberField);
        // Check to see if the user's number is correct
        boolean isCorrect = GuessEngine.testGuess(mUserInput);

thanks in advance for your help :)!

4 Answers

Ben Jakuben
STAFF
Ben Jakuben
Treehouse Teacher

Hey Stefan! Sorry you're having trouble!

I might have to revisit the wording of this one, so let me know what you think once you complete it. Check out the data type of mUserInput. It's not an EditText, but the part you have on the right side of the equals sign is trying to get an EditText from the layout.

That type of work is often done in the onCreate() method, which has been omitted from this challenge to focus on the code we care about. It might clarify if I add it back in, though...I'll think about this challenge and see.

Anyhow, assume that mNumberField is initialized to an appropriate EditText, so now you need to set mUserInput from mNumberField (like setting a String username from the mUsernameField in the video).

larsfredrik
larsfredrik
2,943 Points

I'm sorry but I don't understand that answer... Could someone please post the answer so I could see what I did wrong? :)

Thanks in advance! ^_^

john appleby
john appleby
2,773 Points

Hey Lars... it is worded strange but here is the code. the value to the right of the "=" is assigned to the variable on the left ... hope this helps your learning curve.

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

public class GuessNumberActivity extends Activity {

protected String mUserInput;
protected EditText mNumberField;

// onCreate() and other code has been omitted

public void makeGuess() {
    // Set mUserInput here!

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


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

}

}

larsfredrik
larsfredrik
2,943 Points

Thank you so much, I were so close! Sorry if I worded it strangly, I'll try to improve!

daniwao
daniwao
13,125 Points

This question could use a little re-wording. I try to not look at help when doing code challenges but this one was really tough. I didn't understand what the question was asking me for.

Here is a link to the challenge: http://teamtreehouse.com/library/error-messages-with-dialogs

..and since Stefan started out this thread by saying:

"Sorry if I couldn't copy and paste the whole challenge question but the popup covered the question..."

I'll provide the actual question:

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