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 Creating a New User on Parse

Javier Muñoz Carroz
Javier Muñoz Carroz
4,892 Points

Code not working for the 3rd question in the "Adding Users Using Parse.com" code Challenge.

The final question for this code challenge says: "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!"

My question here is simple. I don't see any error in my code or any reason why it should not work, and yet the web compiler tells me that I have an error. It says " Bummer! Make sure you use the 'Log.e()' method to log the message from the instructions!"

I have already tried this code in my actual app and it works correctly. Why does it not work for the code challenge?

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() {
          @Override
          public void done(ParseException e) {
            if(e==null) {
              //do nothing       
            }
            else {
              Log.e(TAG, "ERROR");
            }
          }
      });
    }
}

3 Answers

Joseph Bogaert
Joseph Bogaert
10,505 Points

Hello. So I think I found your problem..

"Inside the done() method of the callback..."

Which would be:

protected SignUpCallback mSignUpCallback = new SignUpCallback() {
        @Override
        public void done(ParseException e) {
   //Code goes here
        }
    };

And I think you have the actual code part down pat, just in the wrong place, I think. Hope this helps :)

" 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!""

So I think it should look like:

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) {
          if(e == null) {
          //Success!!
          } else {
            Log.e(TAG, "ERROR");
          }

        }
    };

    // 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(mSignUpCallback);

    }
}
David Kaneshiro Jr.
David Kaneshiro Jr.
29,247 Points

You might want to try rewriting your if statement to check if e is NOT equal to NULL and then calling the Log.e function. The code challenge might be looking for you write the code differently? ''' if ( e != NULL) '''

Javier Muñoz Carroz
Javier Muñoz Carroz
4,892 Points

Does not work either. Also, the question itself states that you must check if the ParseException e is null and then if it is not to call the Log. Good suggestion but still not working.

Javier Muñoz Carroz
Javier Muñoz Carroz
4,892 Points

Joseph thank you so much. It is just weird that they already have the SignUpCallback created for you, I had not payed attention to that section of the code as it has not comments or indications and I was trying to do it by creating a new SignUpCallback.

Truly appreciate it.

Joseph Bogaert
Joseph Bogaert
10,505 Points

You're very welcome, sometimes the code challenges can be tricky :)