Welcome to the Treehouse Community

The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.

Android Build a Self-Destructing Message Android App Adding Users Using Parse.com Creating a New User on Parse

i need help with this part of my code

Inside the done() method of the callback, add an if statement to check if the ParseException e is null. If it is not null, log the message "ERROR" using the Log.e() method. Don’t forget to use TAG as the first parameter!

SignUpActivity.java
import android.app.Activity;
import android.util.Log;
import com.parse.ParseUser;
import com.parse.ParseException;
import com.parse.SignUpCallback;

public class SignUpActivity extends Activity {

    public static final String TAG = SignUpActivity.class.getSimpleName();

    protected SignUpCallback mSignUpCallback = new SignUpCallback() {
        @Override
        public void done(ParseException e) {

        }
    };

    // onCreate() and other code has been omitted

    protected void signUp(String username, String password) {
      ParseUser newUser = new ParseUser();
      newUser.setUsername(username);
      newUser.setPassword(password);
      newUser.signUpInBackground(new SignUpCallback(){
      });

    }
}

1 Answer

Hi there,

Two things on this.

First, you've not used the callback that has already been set up for you. So if you change:

      newUser.signUpInBackground(new SignUpCallback(){
      });

to this:

newUser.signUpInBackground(mSignUpCallback);

that uses the variable that has already been created. Then you need to check for the error in the done method.

You can use an if statement to test that. So, " if the error variable contains nothing, great!, else, log the error. That looks like:

        public void done(ParseException e) {
          if(e == null){
           // success!  
          } else {
            Log.e(TAG, "ERROR");
          }
        }

I hope that helps.

Steve.