Get table data with Id value

Hello,
In a table called ANSWERS all rows are identified with an unique Id. With entering an Id, I want to retrieve all of the columns for this row and save it in different variables.
My code is:

String whereClause = "Id = 'id2'";
DataQueryBuilder queryBuilder = DataQueryBuilder.create();
queryBuilder.setWhereClause(whereClause);
Backendless.Data.of( "ANSWERS" ).find( queryBuilder,
        new AsyncCallback<List<Map>>(){
            @Override
            public void handleResponse( List<Map> foundContacts )
            {
                // every loaded object from the "Contact" table is now an individual java.util.Map
            }
            @Override
            public void handleFault( BackendlessFault fault )
            {
                // an error has occurred, the error code can be retrieved with fault.getCode()
            }
        });

I get this error when run my app:

 java.lang.ClassCastException: java.lang.Object[] cannot be cast to java.util.List

Anyone can help me??
Thanks! :slight_smile:

Hi Marc,

I just tried this operation with the latest version of the SDK for Android and it works just fine. Could you please check what version of the SDK you’re building with?

Regards,
Mark

Hi Mark,

I have this compile sentence in my build app gradle file… So the v.4.0.0-beta1

compile 'com.backendless:backendless:4.0.0-beta1'

The latest one is 4.0.0-beta4. Please make sure to update to that version and try again.

Okay, thank you very much!
Seems that now is working! But how i put this data in variables? Where is this saved?

:slight_smile:

When the data is retrieved from the server you would take it our of the returned collection and do whatever you need with it.

But, where is the returned collection?

Sorry if my question is basic… I’m new in Android Studio and java!

Thanks!

Right there in the responder method - the “foundContacts” argument has your objects from the server:

public void handleResponse( List<Map> foundContacts )
{
// every loaded object from the "Contact" table is now an individual java.util.Map
}

Okay… and do you know what should be the code to get the value of the second column, for example?

You should reference the columns by their names. I would recommend inspecting the contents of “foundContacts” with a debugger to see how the data is structured.

Here’s the code to get the first object from the returned collection and then getting a value for a column:

Map firstObject = foundContacts.get( 0 );
//assuming the value in the column is String
String columnValue = (String) firstObject.get( "COLUMN NAME GOES HERE" ); 

OMG, you are really fast!
It works, thank you very much for all!