Tom
Tom

Reputation: 57

You must create this type of ParseObject using ParseObject.create() or the proper subclass. - crashed app but code is correct

When i'm trying to log in error appears and aplication is closing.

java.lang.IllegalArgumentException: You must create this type of ParseObject using ParseObject.create() or the proper subclass.

This is communicate and its showing me that ParseUser user = new ParseUser(); is wrong but its not.

public class RegisterScreen extends AppCompatActivity {

    EditText edUsernameReg,edPasswordReg;
    Button registerBtn;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_register_screen);

        edUsernameReg = (EditText)findViewById(R.id.edUsernameReg);
        edPasswordReg = (EditText)findViewById(R.id.edPasswordReg);
        registerBtn = (Button)findViewById(R.id.registerBtn);

        registerBtn.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                String username = edUsernameReg.getText().toString();
                String password = edPasswordReg.getText().toString();

                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(getApplicationContext(),"Parse signup error", Toast.LENGTH_SHORT).show();
                        }else{
                            Toast.makeText(getApplicationContext(),"Successfully registered!", Toast.LENGTH_SHORT).show();
                            Intent intent = new Intent(RegisterScreen.this,LoginScreen.class);
                            startActivity(intent);
                        }
                    }
                });
            }
        });
    }
}

I was looking for tutorials but all of them are based exactly on documentation so am i. Please help.

Upvotes: 5

Views: 1721

Answers (2)

Joel
Joel

Reputation: 483

Make sure you have added

<application
   android:name=".App"
   ...>
   ...
</application>

to your AndroidManifest.xml file. Here App is the class where the API keys are/the class that initializes Parse

Upvotes: 1

Paras Khanagwal
Paras Khanagwal

Reputation: 1673

The most people do mistake including me is Make sure on every launch your code don't skip the Parse.initialize() call. Parse initialize register your classes every time you launch app. Register your subclasses before calling Parse.initialize()

You can check if user is already logged in before calling logInInBackground().

ParseUser currentUser = ParseUser.getCurrentUser();

    if(currentUser!=null){
       // user is already logged in, do what you want
    }
    else{
        showLoginUI();
    }

Upvotes: 0

Related Questions