Reputation: 124
I've got a simple log in/signup form for an app I'm developing as part of a course. I'm using ParseUser to sign up users and log them in.
When the user enters a username that already exists, a Toast is shown...
ParseUser user = new ParseUser();
user.setUsername(username);
user.setPassword(password);
user.signUpInBackground(new SignUpCallback() {
@Override
public void done(ParseException e) {
if (e == null) {
Toast.makeText(MainActivity.this, "Sign up successful!", Toast.LENGTH_SHORT).show();
} else {
Log.i("Sign up", "failed. Reason - " + e.toString());
Toast.makeText(MainActivity.this, "Sign up failed. " + e.getMessage(), Toast.LENGTH_SHORT).show();
}
}
});
...with the error message from e.getMessage()
, e.g., "Sign up failed. Account already exists for this username."
However, if the user does not enter anything, i.e., leaves either the pw or username field blank, I get this in the app
and the following in the logs: I/Sign up: failed. Reason - com.parse.ParseException: java.lang.IllegalArgumentException: Username cannot be missing or blank
What I want to see is only the error message Username cannot be missing or blank
, which is the ".getMessage()" of the second exception java.lang.IllegalArgumentException
How would I go about doing that? Thanks!
Upvotes: 2
Views: 795
Reputation: 696
There are two main options I see here:
getCause()
, and call getMessage()
on the cause, rather than from the top level exception itself. Upvotes: 2