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 trialcbcbcb
16,560 PointsEvery 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
43,828 PointsHey 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
43,828 PointsHey 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
43,828 PointsHey 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.
cbcbcb
16,560 PointsI 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
cbcbcb
16,560 PointsThanks. 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.
cbcbcb
16,560 PointsPassing 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
cbcbcb
16,560 PointsDo you see where I am going with this?