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

need help with Handling errors using dialogs Android Code Challenge!

need help with task 4 need help with Handling errors using dialogs code challenge for android development, it's probably something simple but it ask me "Finally, create an AlertDialog variable using the Builder's 'create()' method and then display it to the user.

here is my code and it keeps coming up Compilation error

AlertDialog.Builder builder = new AlertDialog.Builder(this); builder.setTitle(getString(R.string.dialog_title)) builder.setMessage(getString(R.string.dialog_message)); AlertDialog dialog = builder.create(); dialog.show();

2 Answers

What did you work out?

Was it something like this:

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 = mNumberField.getText().toString();

        // Check to see if the user's number is correct
        boolean isCorrect = GuessEngine.testGuess(mUserInput);
        if(isCorrect == true){
          AlertDialog.Builder builder = new AlertDialog.Builder(GuessNumberActivity.this);
          builder.setTitle("Hooray!");
          builder.setMessage("You did it!");
          AlertDialog dialog = builder.create();
          dialog.show();
          }
    }
}

never mind, just worked it out