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

Every time I get to step five it invalidates step #3 and wants me to start the entire challenge over again

Every time I get to step five it invalidates step #3 and wants me to start the entire challenge over again

<pre> <code>

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 for brevity!
     */

    public void makeGuess() {
        // Set mUserInput here!        
                mUserInput = new String( mNumberField.getText( ).toString( ) );
        // Check to see if the user's number is correct
        boolean isCorrect = GuessEngine.testGuess(mUserInput);

      if( isCorrect )
      {

        AlertDialog.Builder builder = new AlertDialog.Builder( this );
        builder.setTitle( "Hooray!" );
        builder.setMessage( "You did it!" );

        AlertDialog alert = new AlertDialog( builder );
        builder.show( );

      }

    }

}

</code> </pre>

7 Answers

Calvin Nix
Calvin Nix
43,828 Points

Hey Christopher,

Yeah I understand what you mean.

The problem is how do you define correct code? (In a code-challenge)

There must be some type of check in task 3 that checks whether the user created an AlertDialog object without .Builder. This would make sense to include because I could see how that would be a very common mistake to make.

Yes, in practice, creating an AlertDialog object would have no affect on an AlertDialog.Builder object but since this is a code challenge where checks are placed in the background to see whether the code is correct, this is likely why you are experiencing issues.

Calvin Nix
Calvin Nix
43,828 Points

Hey Christopher,

The reason that you are having issues is with the following lines of code...

AlertDialog alert = new AlertDialog( builder );
        builder.show( );

By making modifications to this I was able to complete the challenge. I'd suggest to re-watch the previous video to see how to accomplish this.

Thanks,

Calvin Nix
Calvin Nix
43,828 Points

Hey Christopher,

Whenever I re-input the code you provided it simply tells me that task three is no longer passing.

It doesn't make me restart all five steps.

I understand that being incorrect and using the create method instead of an overloaded constructor but the question is about invalid input at step five causing me to restart all five steps in the challenge instead of just step 5

Thanks. That is what I meant. Start over at step three. I guess I was under the impression that if I don't change any of my prior code that it shouldn't change my status on previous steps since nothing was modified and only code was appended.

Passing an instance of AlertDialog.Builder as a parameter to AlertDialog's constructor regardless that it was incorrect doesn't change the state of the AlertDialog.Builder object

Do you see where I am going with this?