Trouble with Users Table

String whereClause = “username = '” + s + “’”;
DataQueryBuilder queryBuilder = DataQueryBuilder.create();
queryBuilder.setWhereClause(whereClause);

            Backendless.Data.of("Users").find(queryBuilder, new AsyncCallback<List<Map>>() {

                @Override
                public void handleResponse(List<Map> response) {

e
Log.d(getClass().getName(),“Response:”+response.toString());// always empty
String username = response.get(0).get(“username”).toString();// crashes

                    editTextUsername.setError(username+" Unavailable", Drawable.createFromPath("@drawable/ic_custom_logo_g"));
                }

                @Override
                public void handleFault(BackendlessFault fault) {

                    //username available
                   

                }
            });

In this code fragment the response object is always empty no matter the value of string s
I have a user with username = “tester” in the Users table, but running this code with s=“tester” still returns an empty response object

Hi, @Nkekere_Tommy_Minimann

I believe the issue is in the where clause statement. Please, take a look at this doc - Search with the Where Clause - Backendless SDK for Android/Java API Documentation

Regards,
Marina

I’ve cross checked it, there seems to be no problem with my where clause

Does that where clause work in our REST console? If so, could you please attach a screenshot?

@Nkekere_Tommy_Minimann, please provide your appId

Regards,
Marina

APPLICATION ID = “C2AE98FF-1A1D-BF10-FF3E-64CD97C40D00”;
Where username = ‘tester’ works in the Rest console

Could you show a screenshot of it working please?


It looks like the quotes in the screenshot around the word tester are different than here:

Am using single quotes around the username like this → ‘tester’ both in code and the REST console.

‘tester’

and

'tester'

are different. The second one is correct, the first one will cause problems in the code.

I use exactly the same quotes around productId in this code and it works fine.
Backendless.Data.of(“Master”).update(“productId = '” + productId + “’”, masterChanges, new AsyncCallback() {
@Override
public void handleResponse(Integer objectsUpdated) {

                Log.d(getClass().getName(),"Master Record updated:"+productId);
                progressBar.hide();

            }

            @Override
            public void handleFault(BackendlessFault fault) {

               
            }
        });

@Nkekere_Tommy_Minimann, do you get the required result when you change the code like?

  String whereClause = "username = '" + s + "'";
        DataQueryBuilder queryBuilder = DataQueryBuilder.create();
        queryBuilder.setWhereClause(whereClause);

        List<Map> result = Backendless.Data.of( "Users" ).find( queryBuilder );
        System.out.println( "Response:" + result.toString() );
        String username = result.get( 0 ).get( "username" ).toString();
        System.out.println( username );

No I don’t get the required result with the above code. I still get a null response object that causes the app to crash when I try to access it.

Right here is a blocking call, it will not run on the main UI thread and will result in the app crashing:

List<Map> result = Backendless.Data.of( "Users" ).find( queryBuilder );

In the original code snipper you posted, I’d only change this line:

String whereClause = "username = '" + s + "'";