我在我的Android应用程序的应用程序类中放置了以下代码:
// 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);
每当我全新安装我的应用程序并创建新的Results对象时,这似乎很有用。现在,如果我通过Play商店更新我的应用程序,或通过Android Studio安装它,每当创建新的Results对象或任何其他ParseObject或其子类时,我都会收到以下错误:
java.lang.IllegalArgumentException: cannot setReadAccess for a user with null id
这是Parse的错误吗?我使用Offline Todo示例得到了相同的结果。
答案 0 :(得分:6)
您需要确保保存当前用户。
// 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);
我不完全确定我的语法,我只在Swift中完成。
答案 1 :(得分:3)
从设备中删除应用,然后重新安装。它应该工作。
这是我的设置
//Parser App Crash Report
ParseCrashReporting.enable(this); //THIS is to test only => throw new RuntimeException("Test Exception!");
// Enable Local Datastore.
Parse.enableLocalDatastore(this);
// Initialise
Parse.initialize(this, PARSE_APP_ID, PARSE_CLIENT_KEY);
ParseUser.enableAutomaticUser();
ParseUser.getCurrentUser().saveInBackground();
ParseACL defaultACL = new ParseACL();
// If you would like all objects to be private by default, remove this line.
defaultACL.setPublicReadAccess(true);
ParseACL.setDefaultACL(defaultACL, true);
然后测试:
ParseObject testObject = new ParseObject("TestObject");
testObject.put("foo", "bar");
testObject.put("2", "2");
testObject.put("3", "3");
testObject.saveInBackground();