ParseRequestException:找不到更新的对象

时间:2015-07-15 01:46:07

标签: android parse-platform push-notification

我正在实施解析推送通知,并且在保存推送通知定位的自定义对象时收到以下错误。

以下是我在OnCreate类的Application方法中初始化解析的方法

Parse.initialize(context, PushNotificationManager.PN_APPLICATION_ID_PROD, PushNotificationManager.PN_CLIENT_KEY_PROD);
final ParseInstallation installation = ParseInstallation.getCurrentInstallation();
installation.saveInBackground(new SaveCallback() {
            @Override
            public void done(ParseException e) {
                 if(e != null)
                installation.saveEventually();
            }
         });

稍后在我的代码中,我保存/更新了一些对象:

final ParseInstallation installation = ParseInstallation.getCurrentInstallation();
        installation.put(KEY_SOME_KEY, true);
        installation.put(KEY_ANOTHER_KEY, some_string);
        installation.saveInBackground(new SaveCallback() {
            @Override
            public void done(ParseException e) {
                e.printStackTrace();
                if(e != null)
                    installation.saveEventually();
            }
        });

在调用saveInBackground()时,我收到以下错误,我的对象未更新:

com.parse.ParseRequest$ParseRequestException: object not found for update
com.parse.ParseRequest.newPermanentException(ParseRequest.java:391)
com.parse.ParseRESTCommand.onResponse(ParseRESTCommand.java:197)
com.parse.ParseRequest$3.then(ParseRequest.java:258)
com.parse.ParseRequest$3.then(ParseRequest.java:254)
bolts.Task$14.run(Task.java:796)
bolts.BoltsExecutors$ImmediateExecutor.execute(BoltsExecutors.java:105)
bolts.Task.completeAfterTask(Task.java:787)
bolts.Task.continueWithTask(Task.java:599)
bolts.Task.continueWithTask(Task.java:610)
bolts.Task$12.then(Task.java:702)
bolts.Task$12.then(Task.java:690)
bolts.Task$14.run(Task.java:796)
java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1112)
java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:587)
java.lang.Thread.run(Thread.java:818)

可能出现什么问题?

2 个答案:

答案 0 :(得分:0)

请按以下方式初始化解析,而不是如官方文档(v1.7)

中所示
// Enable Local Datastore.
Parse.enableLocalDatastore(this);

// Add your initialization code here
Parse.initialize(this, "*******", "******");

ParseUser.enableAutomaticUser();
ParseACL defaultACL = new ParseACL();

ParseACL.setDefaultACL(defaultACL, true);

// save the installation
ParseInstallation.getCurrentInstallation().saveInBackground(); 

答案 1 :(得分:0)

这可能是因为Parse注意到本地ParseInstallation对象已更改,并且在下一次调用saveInBackground()时,只发送“脏”列,但该对象尚未在服务器上,因此出现此错误。

对我有用的是:

final ParseInstallation pi = ParseInstallation.getCurrentInstallation();
pi.saveInBackground(new SaveCallback() {
    @Override
    public void done(ParseException e) {
        // Once the object is already saved, update it and save it again
        if (e == null) {
            pi.put("KEY1", "value1");
            pi.put("KEY1", "value1");
            pi.saveInBackground();
        } else {
            Log.d (TAG,"Failed to save parseInstallation");
            Log.d (TAG, "Printing stacktrace ...");
            e.printStackTrace()
        }
    }
});