4

I have a parse class named "classA". I want to build a query where I want to search for rows in "classA" having certain "objectId". I have written the following code. But it always returns an empty list of ParseObjects. I have tried with separate columns existing in "classA". All the time, empty list returned. Please help.

I have used this query before on another class "classB" inside the same application and that works perfectly. I have also tried, "try-catch" block implementation using "query.find". That also returns empty list. Thanks in advance. Please explain what's wrong.

Need more code snippets, please let me know.

    Button btn = (Button) findViewById(R.id.query_btn);
    btn.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            EditText objIdET= (EditText) findViewById(R.id.obj_id);
            String objId= objIdET.getText().toString();
            Log.d("check", objId); // Prints correct value here..

            ParseQuery<ParseObject> query = new ParseQuery<ParseObject>("classA");
            fridgeID.whereEqualTo("objectId", objId);
            List<ParseObject> lp = new ArrayList<ParseObject>();
            query.findInBackground(new FindCallback<ParseObject>() {
                @Override
                public void done(List<ParseObject> objects, ParseException e) {
                    Log.d("#results", String.valueOf(objects.size()));
                }
            });

            }
        }
    });

5 Answers 5

1

Replace FridgeId with query

ParseQuery<ParseObject> query = new ParseQuery<ParseObject>("classA");
            query.whereEqualTo("objectId", objId);
            List<ParseObject> lp = new ArrayList<ParseObject>();
            query.findInBackground(new FindCallback<ParseObject>() {
                @Override
                public void done(List<ParseObject> objects, ParseException e) {
                    Log.d("#results", String.valueOf(objects.size()));
                }
            });
Sign up to request clarification or add additional context in comments.

1 Comment

Check your column and Class name in Parse,it is Case Sensitive
0

Use getInBackground() if you have objectId of that row.

ParseQuery<ParseObject> query = ParseQuery.getQuery("classA");
query.getInBackground(objId, new GetCallback<ParseObject>() {
 public void done(ParseObject object, ParseException e) {
     if (e == null) {
         Log.d("#results", String.valueOf(objects.size()));
     } else {
         // Handle the error
     }
 }
}

Call findInBackground() if you don't have objectId and setting some condition. You can also set condition on objectId field like this.

ParseQuery<ParseObject> query = ParseQuery.getQuery("classA");
query.whereEqualTo("objectId", objId);
query.findInBackground(new FindCallback<ParseObject>() {
 public void done(List<ParseObject> objects, ParseException e) {
     if (e == null) {
         Log.d("#results", String.valueOf(objects.size()));
     } else {
         // Handle the error
     }
 }
}

5 Comments

Thanks. But, still not working. I have checked further. It is not working only in the particular activity. The same query is producing correct result inside MainActivity. Any solution?
have you got any exception?
I am printing the error. Returns this - Error﹕ no results found for query
Then maybe you are calling wrong class name or wrong objectId for that class. please check your objectId in Parse dashboard for that class.Also check for your correct project if you are using two different project for testing and development.
No, the class name is correct. It stopped working from other activities (including Main) as well. Is there any restriction on number of classes I can create and query with a free account?
0

You are getting an empty list of Parse objects because there aren't any rows corresponding to the user (which you are logged in with).

Parse.com implements privacy of its data by using a field called ACL. So if user A adds an entry to your table, by default the ACL is set to Read+Write for User A and none for other users. So user B will not be able to find any objects of userA.

To read more : https://parse.com/docs/android/guide#security

If you want to create a mechanism by which only users belonging to a certain group can read+write each other's objects, you can Roles (Parse feature).

https://parse.com/docs/android/guide#roles

Comments

0

Check if you have set the correct keys when you initialize the parse in your application.

Comments

0

If you want to get list of users, and ParseQuery.getQuery doesn't work - try this:

val query: ParseQuery<ParseUser> = ParseUser.getQuery()
    query.findInBackground() {...}

Comments

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.