Replication addchangelistener

Hi , i am trying to implement the addchange listener, but RemoteRequestResponseException does not exists in my programme, i was wondering if anyone can advice me on this.

pull.addChangeListener(new Replication.ChangeListener() {
public void changed(Replication.ChangeEvent event) {

            if (event.getError() != null) {
                Throwable lastError = event.getError();
                if (lastError instanceof RemoteRequestResponseException) {
                    **RemoteRequestResponseException** exception = (**RemoteRequestResponseException)** lastError;
                    if (exception.getCode() == 401) {
                        // Authentication error

I don’t know what the ** characters refer to in your code snippet.

If it is an instance of RemoteRequestResponseException then you can downcast it to that type, see


Hey James, that part is nothing actually. I wanted to bold those worlds. Could you please elaborate on what downcast type is? My top code is from that link you send me

Hope to hear from you soon :slight_smile:

That code snippet should work. Make sure the import com.couchbase.lite.replicator.RemoteRequestResponseException; is imported in your class file. What version of CBL are you running?


Hey James,

It seems i don’t have that class. com.couchbase.lite:couchbase-lite-android:1.2.1.

Oh I see, prior to 1.3 the exception is called HttpResponseException (based on Apache’s HttpClient). In CBL Android 1.3, HttpClient is replaced by OkHttp.

I’d suggest to upgrade to CBL 1.3 if you can. Otherwise you might want to include HttpClient in your Android Studio project (deprecated in Android API 23 and above)


Thanks so much James:)