Trying to save search files from DataBase

So I’m trying to get posts from my database, including names, descriptions, and images, all this is already saved in my backendless but I’m really having a lot of trouble trying to retrieve this information and save it so I can use it or display it.

This is my code on that topic:

    String whereClause = "groups.objectId = '" + groupObjectId + "'";

    DataQueryBuilder queryBuilder = DataQueryBuilder.create();

    //Encontrar na base de dados as publicações relacionadas com este grupo
    Backendless.Persistence.of(Posts.class).find(queryBuilder, new AsyncCallback<List<Posts>>() {
        public void handleResponse(List<Posts> response) {
            int size = response.size();
            Log.d("size", "size"+ size);
            for( Posts p : response){
                Posts pT = new Posts();
            Bundle b = new Bundle();
            b.putParcelableArrayList("lstPosts", postToPass);
            b.putString("groupId", groupObjectId);
            FeedFrag feedFrag = new FeedFrag();

        public void handleFault(BackendlessFault fault) {
           Log.d("INFO","failed to search");
            Toast.makeText(MainActivity.this, "Error on gathering posts", Toast.LENGTH_SHORT).show();

My postToPass gets a size of 0 when adding it to the bundle, so I’m getting a NullPointer. I just don’t know how to solve it and save the posts inside that array.


  1. Have you tested the where clause in Backendless console?
  2. Have you tried running your code in a debugger?


Hey Mark,

  1. I haven’t, I don’t know how to…
  2. I’ve ran the code in debugging and find that the size would be 0, but my for doesn’t seem to run.

Thank you Mark,

See this article:

In the REST Console form there is Where field, this is where you can put your where clause to test it.


I’ve tested the whereClause finding it was wrong, but I’m not being able to do it. So I have a groups Table that contains the users and posts with relations to it. How can I get the all the posts of a given group? Is it with the whereClause? Because that was what I was trying to do.

Thank you Mark,

I mean, how can I turn this posts into a Post object?

Does the Group class have a field/property with the type of List<Posts>?

No, but it has a relation with the Posts class, 1:N. I’d like to retrieve the relation, or each post to a Post Object, or all the posts to an Array

What does this mean in terms of code? How does it have that relation at the code level?

I meant this Mark.
In Group Table:

As you can see theres a Relation to Posts.
In Posts Table:
There’s a relation FROM Group,

With this I want to know how can I get the objects posts related (via relation) to a certain group.

My question is not about the schema in the database, I got that part. The question is how you structured it in the code, because that’s what you were asking about.

Well, I do the code I showed you in the beginning of my Main Activity where I use the FeedFrag on a ViewPager with a Fragment Manager, but the thing is that the WhereClause actually doesn’t work. I didn’t quite get what you mean by how I did structured it in the code, but not being able to get the posts, so I can’t save them into object and display them. Thanks to you I’ve found out that the WhereClause was the problem but still don’t know how to change it and get the relation from the groups with the posts.

You can use Single Step Retrieval or Two Step retrieval to get the Post objects knowing the Group objectId. I assume the last example from this documentation is exactly what you need:

LoadRelationsQueryBuilder<BackendlessUser> loadRelationsQueryBuilder; 
loadRelationsQueryBuilder = LoadRelationsQueryBuilder.of( Group.class );
loadRelationsQueryBuilder.setRelationName( "posts" );

String groupObjectId = // removed for brevity
Backendless.Data.of( Group.class ).loadRelations( groupObjectId,
        new AsyncCallback<List<Posts>>()
          public void handleResponse( List<Posts> posts )
          public void handleFault( BackendlessFault fault )


1 Like

That was the solution for the problem. But I have one last problem, I’m now able to get the posts I wanted, and I can use them. But because of the Asynchronous call the application crashes before getting the all the values it needs, only working if I pass it through debug step by step.
Any solution for this? Any way I can delay the main thread?

what does the crash error message say? Is there any helpful information?

I’m sending a print.

No matter what getArguments goes first, since the Asyncallback isn’t yet finished it gets null values.

Hi @Alexandre_Coutinho,

It seems to me the code tries to access the result of the invocation before it is available. You need to refactor the code so that the response processing starts only after you actually get the response.

Does it make sense?


Yes mark it does make sense! But how do I do it? I’ve fixed it by creating that asyncallback on the activity before my main one, but still… I’d like to have it the way I had, this is, in the Main Activity

One way to do this is to put the code that works with the response data into the handleResponse method. Another way to do this is to create a separate activity which works with the response data and dispatch an intent with the response into that activity.

1 Like