Subscribing Error || Android

Hello
I ‘m getting error when trying to subscribe to channel The error code is 5009 and the message ’ error during subscription ’
Maybe that’s because of the query in the selector … But I’m sure it’s right … that’s the code :
final SubscriptionOptions options = new SubscriptionOptions();
StringBuilder selector = new StringBuilder();
selector.append(“from = '”).append(name).append("’")
.append(" AND to: = ‘").append(current_name).append("’");
selector.append(" OR from = ‘").append(current_name).append("’");
selector.append(" AND to: = ‘").append(name).append("’");
options.setSelector(selector.toString());

Backendless.Messaging.subscribe(“privateChat”, new AsyncCallback<List<Message>>() {
@Override
public void handleResponse(List<Message> messages) {
}
@Override
public void handleFault(BackendlessFault backendlessFault) {
Toast.makeText(privateChat.this,backendlessFault.toString(),Toast.LENGTH_SHORT).show();
}
},options, new AsyncCallback<Subscription>() {
@Override
public void handleResponse(Subscription subscription) {
Toast.makeText(privateChat.this,“subscribed”,Toast.LENGTH_SHORT).show();
}
@Override
public void handleFault(BackendlessFault backendlessFault) {
Toast.makeText(privateChat.this,backendlessFault.toString()+ backendlessFault.getMessage()+ backendlessFault.getDetail()+backendlessFault.getCode(),Toast.LENGTH_SHORT).show();
}
});
And thanks

Hello!
You have mistakes in the selector: remove “:” after words “to” in the following rows:
.append(" AND to: = ‘").append(current_name).append("’");

selector.append(" AND to: = ‘").append(name).append("’");

best regards,
Alex Navara

When I’m publishing message I’m putting header :

publishOptions.putHeader(“to:”, name); if I removed the “:” it will work ?

It will put it on the right track… whether it will work or not, depends on other bugs present in your code :slight_smile:

Yes, that’s right. Selector which contains “:” wouldn’t pass validation. Do not forget that selector is a query expressed using the SQL-92 syntax.

so that mean any SQL statment should work right ?

most of it, but specifically only the part that goes into SQL’s “WHERE” clause.

it worked ! Thank you Alexandr, Mark
But please I have a question : if I subscribed to a channel but the channel is empty or there isn’t any messages … The code in handle response run or what ?

If channel has no messages, then your messaging handler is not called until the channel has messages.

when I send message to “privateChat” channel , the code in the subscribe call should run right ? I mean after subscribe to channel , It will return the list of messages in the channel . but if there isn’t any messages it will wait until new message is published then it will run … but why my code in handleResponse isn’t running even if a user send message to the channel ?it’s because selector ? but I’m sure the SQL query is work ! I’ll post my code soon

and thanks for supporting me ! your support section is really helpful (y)

that’s my code :

final SubscriptionOptions options = new SubscriptionOptions();
StringBuilder selector = new StringBuilder();
selector.append("from = '").append(name).append("'")
        .append(" AND to = '").append(current_name).append("'");
selector.append(" OR from = '").append(current_name).append("'");
selector.append(" AND to = '").append(name).append("'");
options.setSelector(selector.toString());
Backendless.Messaging.subscribe("privateChat", new
    AsyncCallback&lt;List&lt;Message&gt;>() {
    @Override
    public void handleResponse(List&lt;Message&gt; messages) {
        get();
    }
    @Override
    public void handleFault(BackendlessFault backendlessFault) {}
}, options, new AsyncCallback&lt;Subscription&gt;() {
    @Override
    public void handleResponse(Subscription subscription) {
        get();
    }
    @Override
    public void handleFault(BackendlessFault backendlessFault) {}
});

when A new message is published … the code in the AsyncCallBack<List<Message>> isn’t running

I’ve solved The problem … I’ve just forgot to put the publishOptions in the publish Call …