jainil
jainil

Reputation: 41

username not being accepted?

In the below code Username field is giving an error as shown in the pic not sure why please help??enter image description here

The picture gives the description of the error message that is being received enter image description here

public class MainActivity extends AppCompatActivity {
EditText text;
ParseUser a;
EditText text2;
public void Onclick(View view)
{
    text=(EditText)findViewById(R.id.editText);
    text2=(EditText)findViewById(R.id.editText2);
    if(view.getId()==R.id.button)
    {
        ParseUser.logInInBackground(text.getText().toString(), text2.getText().toString(), new LogInCallback() {
            @Override
            public void done(ParseUser user, ParseException e) {
                if(user!=null)
                {
                    Toast.makeText(MainActivity.this, "Logged in", Toast.LENGTH_SHORT).show();
                }
                else
                {
                    Toast.makeText(MainActivity.this,"invalid username or password", Toast.LENGTH_SHORT).show();
                }
            }
        });
    }
    if(view.getId()==R.id.button2)
    {
     a=new ParseUser();
        a.signUpInBackground(new SignUpCallback() {
            @Override
            public void done(ParseException e) {
                if(e==null)
                {
                    a.setUsername(text.getText().toString());
                    Toast.makeText(MainActivity.this, "user signed in", Toast.LENGTH_SHORT).show();
                    a.setPassword(text2.getText().toString());
                }
                else
                {
                    Toast.makeText(MainActivity.this,"Already user", Toast.LENGTH_SHORT).show();
                    Toast.makeText(MainActivity.this,e.getMessage().substring(e.getMessage().indexOf(" ")), Toast.LENGTH_SHORT).show();
                }
            }
        });
    }
   // ParseAnalytics.trackAppOpenedInBackground(getIntent());
}

Upvotes: 0

Views: 79

Answers (1)

Rudy
Rudy

Reputation: 7044

Upon clicking button2, the a.signUpInBackground() does a checking in background which noticed that the username is empty.

You should populate the username and password before the a.signUpinBackground() and not during Callback ( which will be only run once you finish sign up ), as described in http://docs.parseplatform.org/android/guide/#users, sample as below :

ParseUser user = new ParseUser();
user.setUsername("my name"); //in your case, text.getText().toString()
user.setPassword("my pass"); //in your case, text2.getText().toString()  
user.setEmail("[email protected]");

// other fields can be set just like with ParseObject
user.put("phone", "650-253-0000");

user.signUpInBackground(new SignUpCallback() {
public void done(ParseException e) {
   if (e == null) {
     // Hooray! Let them use the app now.
   } else {
     // Sign up didn't succeed. Look at the ParseException
     // to figure out what went wrong
   }
 }
});

Upvotes: 2

Related Questions