0

I am using the Parse Platform as a backend for my android application.

I have a database / class named 'ClassA' which contains a column relation to a class called 'Announcement'

I am trying to create an announcement and add the relation to the ClassA.

I have tired using the API reference on the official website and also code examples found on programcreek

Announcement announcement = new Announcement();
announcement.setTitle(announcements_title.getText().toString());
announcement.setText(announcements_text.getText().toString());

ParseRelation<Announcement> relation = classA.getRelation("announcements");
relation.add(announcement);
classA.saveInBackground(new SaveCallback() {
...
}

I am currently getting the following error message: java.lang.IllegalStateException: unable to encode an association with an unsaved ParseObject

But i have tried to

announcement.saveInBackground();

before creating the relation but that is not working either

1 Answer 1

1

Try something like:

ParseObject announcement = new ParseObject("Announcement");
announcement.put("title", announcements_title.getText().toString());
announcement.put("text", announcements_text.getText().toString());
announcement.saveInBackground(new SaveCallback() {
    ParseRelation<ParseObject> relation = classA.getRelation("announcements");
    relation.add(announcement);
    classA.saveInBackground(new SaveCallback() {
        ...
    });
});
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.