Search code examples
javaandroidparse-platform

done() function returning null ParseObject


I want to delete a row in the table of database using ParseObject.But I am not able to do so as apparently the done() function is returning a null object. Following is my code for deletion:

"vex" is the table name and "objectId" is the objectId of the table

  Button yes=(Button)layout.findViewById(R.id.byes);
    yes.setOnClickListener(new OnClickListener() {
        @Override
        public void onClick(View view) {
            Toast.makeText(getApplicationContext(),"inside yes!",Toast.LENGTH_LONG).show();
            ParseQuery<ParseObject> query = ParseQuery.getQuery("Vex");
            query.whereEqualTo("objectId", objectId);
            query.getInBackground(objectId, new GetCallback<ParseObject>() {
                @Override
                public void done(ParseObject object, ParseException e) {

                    if (object == null) {
                        Log.d("vque", "The getFirst request failed.");
                    } else {
                        try {
                            object.delete();
                            object.saveInBackground();


                            Toast.makeText(getApplicationContext(), "Deleted Successuly.", Toast.LENGTH_SHORT).show();


                        } catch (ParseException e1) {
                            e1.printStackTrace();
                        }
                    }



                }
            });
}});

Solution

  •  query.whereEqualTo("objectId", objectId);
    

    Inspecting this point I found out that the objectId is null.Hence, this was returning a null ParseObject in the function done().

    I was getting null objectId because i had used this line to retrieve the objectId.

    String objectId=object.getString("objectId");
    

    While I should have rather used:

    String objectId=object.getObjectId();