如何解决java.lang.IllegalArgumentException:对于具有null id的用户,不能setReadAccess?

时间:2015-05-18 10:23:05

标签: android parse-platform

我已检查this link并使用已接受的答案,但我也收到此错误。我的应用程序类代码是:

//Enable Parse crash reports
ParseCrashReporting.enable(this);

// Enable Local Datastore.
Parse.enableLocalDatastore(this);
Parse.initialize(this, "APP_ID", "CLIENT_ID");

ParseUser.enableAutomaticUser();
ParseUser.getCurrentUser().saveInBackground();
ParseACL defaultACL = new ParseACL();
//defaultACL.setPublicReadAccess(true);
ParseACL.setDefaultACL(defaultACL, true);

我的清单文件权限是:

<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.WAKE_LOCK" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" /> 
<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED" />
<uses-permission android:name="android.permission.VIBRATE" />
<uses-permission android:name="android.permission.GET_ACCOUNTS" />
<uses-permission android:name="com.google.android.c2dm.permission.RECEIVE" />

我收到此错误:

  

java.lang.IllegalArgumentException:无法为具有null id的用户设置setReadAccess

on ParseObject photo = new ParseObject("Photo");

Photo ParseClass有五个字符串类型的字段和一个指向User对象的_User类型指针字段。我创建了新的parse对象并将值放在相应的字段中,并将ParseUser.getCurrentUser()放在指针字段中,然后将其放入Parse Local DataStore中,以便可以在离线模式下访问对象。

1 个答案:

答案 0 :(得分:0)

- (void)viewDidLoad { [super viewDidLoad]; // Do any additional setup after loading the view, typically from a nib. UIButton *xbutton = [UIButton buttonWithType:UIButtonTypeCustom]; xbutton.frame = CGRectMake(0, 6, 35, 35); xbutton.backgroundColor = [UIColor redColor]; UIView *containerView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 44, 44)]; UISwitch *switchButton = [[UISwitch alloc] init]; switchButton.frame = CGRectMake(0, 0, 35, 35); switchButton.transform = CGAffineTransformMakeScale(0.55, 0.55); switchButton.center = CGPointMake(containerView.frame.size.width/2, containerView.frame.size.height/2); [containerView addSubview:switchButton]; UIBarButtonItem *additionalButton = [[UIBarButtonItem alloc] initWithCustomView:containerView]; UIBarButtonItem *xBarButton = [[UIBarButtonItem alloc] initWithCustomView:xbutton]; //rearrange it if necessary NSArray *arrayButton = [NSArray arrayWithObjects: xBarButton, additionalButton, nil]; self.navigationItem.leftBarButtonItems = arrayButton; }. 是异步操作,当您尝试将当前用户放到Photo对象时,它实际上并未保存。

尝试将回调添加到您的保存方法,然后将用户保存到保存时。

ParseUser.getCurrentUser().saveInBackground();