Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
357 views
in Technique[技术] by (71.8m points)

android - SetReadAccess error for new ParseObject

I have the following code placed in my application class of an Android app of mine:

// Register ParseObject subclasses
ParseObject.registerSubclass(Results.class);

// Set up Parse
Parse.enableLocalDatastore(MyApplication.this);
Parse.initialize(MyApplication.this, PARSE_APP_KEY, PARSE_CLIENT_KEY);
ParseUser.enableAutomaticUser();
ParseACL defaultACL = new ParseACL();
ParseACL.setDefaultACL(defaultACL, true);

This seems to work great whenever I have a fresh install of my app and I create new Results objects. Now, if I update my app via the Play store, or install over it via Android Studio, I get the following error whenever new Results objects, or any other ParseObject or subclass thereof, are created:

java.lang.IllegalArgumentException: cannot setReadAccess for a user with null id

Is this a bug with Parse? I get the same results with the Offline Todo example.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

You need to make sure to save the current user.

// Register ParseObject subclasses
ParseObject.registerSubclass(Results.class);

// Set up Parse
Parse.enableLocalDatastore(MyApplication.this);
Parse.initialize(MyApplication.this, PARSE_APP_KEY, PARSE_CLIENT_KEY);
ParseUser.enableAutomaticUser();
ParseUser.getCurrentUser().saveInBackground(); // <--- This Line
ParseACL defaultACL = new ParseACL();
ParseACL.setDefaultACL(defaultACL, true);

Not entirely sure about my syntax, I've only done it in Swift.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...