【问题标题】:ParseRequestException: object not found for updateParseRequestException:找不到更新的对象
【发布时间】:2015-07-15 01:46:06
【问题描述】:

我正在实现 Parse Push Notifications,并在保存我的自定义对象以进行推送通知定位时收到以下错误。

这是我在 Application 类的 OnCreate 方法中初始化解析的方式

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)

可能出了什么问题??

【问题讨论】:

    标签: android parse-platform push-notification


    【解决方案1】:

    这可能是因为 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()
            }
        }
    });
    

    【讨论】:

      【解决方案2】:

      请按照以下方式初始化解析,而不是官方文档(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(); 
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2016-11-23
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2018-09-20
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多