3

I'm attempting to create a new ParseObject like so:

ParseObject message = new ParseObject("Message");

When I run the app, it gives me the following error:

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

This is my full code

ParseObject message = new ParseObject("Message");
message.put("content", "words go here");
message.saveInBackground();

More code can be posted if needed. All help is appreciated!

HTG
  • 584
  • 1
  • 8
  • 28
  • 1
    Your full code differs from your first line of code. The second one should work – Tim Mar 19 '15 at 20:20
  • ParseObject message = ParseObject.create("Message"); works completely. – Kishan Vaghela Mar 19 '15 at 20:21
  • @TimCastelijns I've tried both lines. the first line `= new Parseobject("Message");` causes the error, while the `= ParseObject.create("Message");` line does not add anything to the cloud. – HTG Mar 19 '15 at 20:29
  • Have you tried creating a Message class first in the dashboard? – Dave S Mar 19 '15 at 20:33
  • @DaveS there is a `Message` class already on the dashboard. – HTG Mar 19 '15 at 20:38
  • Do you have the latest version of the Parse SDK or an older version? – Dave S Mar 19 '15 at 20:39
  • i am facing same issue when i update data. if i create a new Parse Object than exception arrive is signUp first but i already login in same user – Mehul Tank May 25 '17 at 11:04

3 Answers3

4

From this example: https://parse.com/docs/android_guide#objects

You can create objects like so:

ParseObject gameScore = new ParseObject("GameScore");
gameScore.put("score", 1337);
gameScore.put("playerName", "Sean Plott");
gameScore.put("cheatMode", false);
gameScore.saveInBackground();

In fact similar code works in my app right now.

If you have created a Message model that extends ParseObject you may want to call new Message() as seen in this question:

https://www.parse.com/questions/new-parseobjectchat-crushes-the-app

This answer suggests using .create() may fix the problem but doesn't explain why.

App crash when I submit a new post to Parse

Also make sure you are properly initializing your app with the correct keys and you are using the latest version of the SDK.

Community
  • 1
  • 1
Dave S
  • 3,378
  • 1
  • 20
  • 34
  • i am facing same issue when i update data. if i create a new Parse Object than exception arrive is signUp first but i already login in same user – Mehul Tank May 25 '17 at 11:03
2

Make sure you've initialized Parse in your Application class.

public class MyApplication extends Application {
    @Override
    public void onCreate() {
        super.onCreate();

        // Register your parse models
        ParseObject.registerSubclass(GameScore.class); // for example

        Parse.enableLocalDatastore(this);
        Parse.initialize(new Parse.Configuration.Builder(context)
                .applicationId(APPLICATION_ID)
                .server(SERVER)
                .build()
        );
    }
}
Muz
  • 5,866
  • 3
  • 47
  • 65
1

If you have a subclass, example:

@ParseClassName("Rating")
public class ParseRating extends ParseObject{

You are going to get this error typing new ParseObject("Rating")

The solution is to create a new ParseRating()

Pablo Cegarra
  • 20,955
  • 12
  • 92
  • 110