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

Steve Wamsley
Steve Wamsley
7,977 Points

Syntax error logging ParseException

I keep getting syntax error with the following code in this challenge:

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) {
            Log.e(SignUpActivity.TAG, "ERROR", 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(mSignUpCallback);
    }
}

The syntax error says the Log.e(java.lang.String,java.lang.String,com.parse.ParseException) method cannot be found:

./SignUpActivity.java:15: cannot find symbol
symbol  : method e(java.lang.String,java.lang.String,com.parse.ParseException)
location: class android.util.Log
            Log.e(SignUpActivity.TAG, "ERROR", e);
               ^
1 error

I know the syntax is correct. Is it a problem with the testing engine? Or am I missing something?

Ronny Perez
Ronny Perez
29,956 Points

you are doing great just do

if (e != null) { Log.e(TAG, "ERROR"); }

no need for SignUpActivity.TAG or the e at the end because the if statement is already inside of an exception.This world for me

Ronny Perez
Ronny Perez
29,956 Points

I meant to say this worked** for me. sorry typo :-).

Steve Wamsley
Steve Wamsley
7,977 Points

Thanks for your help. While that got me past the code challenge, I don't believe it's the right answer. For some reason, ParseException is not being recognized as extending from Exception.

3 Answers

Michael Ikhane
Michael Ikhane
2,390 Points

Hi Steve,

I tested "Log.e(TAG, e.getMessage(), e);" on my machine and it ran just fine. Secondly when you open the class declaration for ParseException you will see that it extends Exception.

However, my guess is that the code challenge expected you to use the Log.e method with 2 arguments.

Cheers

I just wanted it noted I also got a ParseException error,

mainly because I put the if code in the wrong place.

Here's everything in the right place:

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) { 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);

    }
}

By the way the link to the challenge is: http://teamtreehouse.com/library/creating-a-new-user-on-parse

and here is the wording of the part 3 of the challenge:

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!

Steve Wamsley
Steve Wamsley
7,977 Points

Not technically the answer to my question, it did get me past the code challenge. Technically, I should be able to use the 3-argument method of Log.e() with the ParseException.