0

I am trying to delete an object from my parse.com class "GameScore" where playerName equals to current player name. I am successfully retrieving the object but deleteInBackground function is not working for me.(Object is not getting deleted from parse.com class. I am new to parse and android both. Can anyone please help.

holder.deleteitem.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {

            //String myname = worldpopulationlist.get(position).getName();

            ParseQuery<ParseObject> query = ParseQuery.getQuery("GameScore");
            query.whereEqualTo("playerName", worldpopulationlist.get(position).getName());
            query.getFirstInBackground(new GetCallback<ParseObject>() {

                @Override
                public void done(ParseObject object, ParseException e) {
                    // TODO Auto-generated method stub
                    if (object == null) {
                        Toast.makeText(context,"  not found",
                                Toast.LENGTH_SHORT).show();
                        } else {
                            object1.deleteInBackground(new DeleteCallback() {
                                           public void done(ParseException e) {
                                                 if (e == null) {
                                                     Toast.makeText(context,"  deleted",
                                                                Toast.LENGTH_SHORT).show();
                                                 } else {
                                                     Toast.makeText(context,"  not deleted",
                                                                Toast.LENGTH_SHORT).show();
                                                     e.printStackTrace();

                                                 }
                                               }
                                             });

                        }
                    }

            });
            Intent intent = new Intent(context, MainActivity.class);
            intent.setFlags( Intent.FLAG_ACTIVITY_NO_HISTORY);
            context.startActivity(intent);

        }


    });

here is the error log. The first line of the log is showing object not found but when I use object.getObjectId() method. it returns the correct objectId of the object.

    07-15 07:21:14.688: I/message(17431): com.parse.ParseException: object not found for delete
07-15 07:21:14.688: I/message(17431):   at com.parse.ParseCommand$3.then(ParseCommand.java:340)
07-15 07:21:14.688: I/message(17431):   at com.parse.Task$10.run(Task.java:442)
07-15 07:21:14.688: I/message(17431):   at com.parse.Task$1.execute(Task.java:67)
07-15 07:21:14.688: I/message(17431):   at com.parse.Task.completeImmediately(Task.java:439)
07-15 07:21:14.688: I/message(17431):   at com.parse.Task.continueWith(Task.java:316)
07-15 07:21:14.688: I/message(17431):   at com.parse.Task.continueWith(Task.java:327)
07-15 07:21:14.688: I/message(17431):   at com.parse.Task$8.then(Task.java:377)
07-15 07:21:14.688: I/message(17431):   at com.parse.Task$8.then(Task.java:1)
07-15 07:21:14.688: I/message(17431):   at com.parse.Task$11.run(Task.java:474)
07-15 07:21:14.688: I/message(17431):   at com.parse.Task$1.execute(Task.java:67)
07-15 07:21:14.688: I/message(17431):   at com.parse.Task.completeAfterTask(Task.java:471)
07-15 07:21:14.688: I/message(17431):   at com.parse.Task.access$9(Task.java:467)
07-15 07:21:14.688: I/message(17431):   at com.parse.Task$7.then(Task.java:343)
07-15 07:21:14.688: I/message(17431):   at com.parse.Task$7.then(Task.java:1)
07-15 07:21:14.688: I/message(17431):   at com.parse.Task.runContinuations(Task.java:502)
07-15 07:21:14.688: I/message(17431):   at com.parse.Task.access$5(Task.java:498)
07-15 07:21:14.688: I/message(17431):   at com.parse.Task$TaskCompletionSource.trySetResult(Task.java:557)
07-15 07:21:14.688: I/message(17431):   at com.parse.Task$TaskCompletionSource.setResult(Task.java:591)
07-15 07:21:14.688: I/message(17431):   at com.parse.Task$11$1.then(Task.java:485)
07-15 07:21:14.688: I/message(17431):   at com.parse.Task$11$1.then(Task.java:1)
07-15 07:21:14.688: I/message(17431):   at com.parse.Task$10.run(Task.java:442)
07-15 07:21:14.688: I/message(17431):   at com.parse.Task$1.execute(Task.java:67)
07-15 07:21:14.688: I/message(17431):   at com.parse.Task.completeImmediately(Task.java:439)
07-15 07:21:14.688: I/message(17431):   at com.parse.Task.access$8(Task.java:435)
07-15 07:21:14.688: I/message(17431):   at com.parse.Task$6.then(Task.java:309)
07-15 07:21:14.688: I/message(17431):   at com.parse.Task$6.then(Task.java:1)
07-15 07:21:14.688: I/message(17431):   at com.parse.Task.runContinuations(Task.java:502)
07-15 07:21:14.688: I/message(17431):   at com.parse.Task.access$5(Task.java:498)
07-15 07:21:14.688: I/message(17431):   at com.parse.Task$TaskCompletionSource.trySetResult(Task.java:557)
07-15 07:21:14.688: I/message(17431):   at com.parse.Task$TaskCompletionSource.setResult(Task.java:591)
07-15 07:21:14.688: I/message(17431):   at com.parse.Task$11$1.then(Task.java:485)
07-15 07:21:14.688: I/message(17431):   at com.parse.Task$11$1.then(Task.java:1)
07-15 07:21:14.688: I/message(17431):   at com.parse.Task$10.run(Task.java:442)
07-15 07:21:14.688: I/message(17431):   at com.parse.Task$1.execute(Task.java:67)
07-15 07:21:14.688: I/message(17431):   at com.parse.Task.completeImmediately(Task.java:439)
07-15 07:21:14.688: I/message(17431):   at com.parse.Task.continueWith(Task.java:316)
07-15 07:21:14.688: I/message(17431):   at com.parse.Task.continueWith(Task.java:327)
07-15 07:21:14.688: I/message(17431):   at com.parse.Task$11.run(Task.java:478)
07-15 07:21:14.688: I/message(17431):   at com.parse.Task$1.execute(Task.java:67)
07-15 07:21:14.688: I/message(17431):   at com.parse.Task.completeAfterTask(Task.java:471)
07-15 07:21:14.688: I/message(17431):   at com.parse.Task.access$9(Task.java:467)
07-15 07:21:14.688: I/message(17431):   at com.parse.Task$7.then(Task.java:343)
07-15 07:21:14.688: I/message(17431):   at com.parse.Task$7.then(Task.java:1)
07-15 07:21:14.688: I/message(17431):   at com.parse.Task.runContinuations(Task.java:502)
07-15 07:21:14.688: I/message(17431):   at com.parse.Task.access$5(Task.java:498)
07-15 07:21:14.688: I/message(17431):   at com.parse.Task$TaskCompletionSource.trySetResult(Task.java:557)
07-15 07:21:14.688: I/message(17431):   at com.parse.Task$TaskCompletionSource.setResult(Task.java:591)
07-15 07:21:14.688: I/message(17431):   at com.parse.Task$3.run(Task.java:225)
07-15 07:21:14.688: I/message(17431):   at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:442)
07-15 07:21:14.688: I/message(17431):   at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:305)
07-15 07:21:14.688: I/message(17431):   at java.util.concurrent.FutureTask.run(FutureTask.java:137)
07-15 07:21:14.688: I/message(17431):   at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.access$201(ScheduledThreadPoolExecutor.java:150)
07-15 07:21:14.688: I/message(17431):   at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.run(ScheduledThreadPoolExecutor.java:264)
07-15 07:21:14.688: I/message(17431):   at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1076)
07-15 07:21:14.688: I/message(17431):   at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:569)
07-15 07:21:14.688: I/message(17431):   at java.lang.Thread.run(Thread.java:856)
2
  • Are you getting an error? Is your "not found" message showing up? Commented Jul 15, 2014 at 0:36
  • @TimothyWalters No, I am not getting any error. It is displaying Deleted. But object is not getting deleted. Commented Jul 15, 2014 at 0:57

2 Answers 2

4

I had a similar problem and my issues was the Parse ACL permissions.

In the class, where you originally created the object (not the class where you would like to delete the object). set the write permissions like below:

    ParseACL defaultACL = new ParseACL();
    defaultACL.setPublicReadAccess(true);
    defaultACL.setPublicWriteAccess(true); //objects created are writable
    ParseACL.setDefaultACL(defaultACL, true);
Sign up to request clarification or add additional context in comments.

1 Comment

Thanks. I have solved the problem with a different approach. I used cloud code to set its ACL while creating the object.
0

It could be that deleteInBackground() is returning an error, or (not sure on the way Android handles this) it is being garbage collected before it is doing the delete.

Consider adding a callback to the delete to at least log the success/error from the delete.

5 Comments

I have added callback now it is showing not deleted. ` object.deleteInBackground(new DeleteCallback() { public void done(ParseException e) { if (e == null) { Toast.makeText(context," deleted", Toast.LENGTH_SHORT).show(); } else { Toast.makeText(context," not deleted", Toast.LENGTH_SHORT).show(); } } });`
Please add that code to your question as an edit below the original, also try logging the contents of the exception, as you now know you're getting an error from Parse when trying to delete.
I have updated the log cat please look at it once. The first line of the log says object not found but when I use object.getObjectId() method. it returns the correct objectId of the object.
Now I understood the problem. It is related to user permissions. One can delete only its own uploads. however I have set the permissions to "Any user can perform this action" still it is not allowing other user to delete.
That's the default for the Class, but it also takes any ACL into consideration, so if you have an ACL set on the object that is used instead. You can get around this using Cloud Functions that use the master key.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.