Cannot delete single object

Hello. My problem is i want to delete single object using delteObject() method which according to algolia, is supposed to need one parameter that is objectID. In my code objectID() method always needs requestOptions as well. Im try to look in docs of some examples of request options or something but those docs are, at least for me, pretty confusing.

public void deleteObject(String objectID) {
    try {
        RequestOptions requestOptions = new RequestOptions();
        index.deleteObject(objectID,requestOptions);
    }
    catch (AlgoliaException e) {
        e.printStackTrace();
    }
}

Error looks like this:

E/AndroidRuntime: FATAL EXCEPTION: main
Process: sk.upjs.ics.android.teazoneinc, PID: 26947
android.os.NetworkOnMainThreadException
    at android.os.StrictMode$AndroidBlockGuardPolicy.onNetwork(StrictMode.java:1513)
    at java.net.Inet6AddressImpl.lookupHostByName(Inet6AddressImpl.java:117)
    at java.net.Inet6AddressImpl.lookupAllHostAddr(Inet6AddressImpl.java:105)
    at java.net.InetAddress.getAllByName(InetAddress.java:1154)
    at com.android.okhttp.Dns$1.lookup(Dns.java:39)
    at com.android.okhttp.internal.http.RouteSelector.resetNextInetSocketAddress(RouteSelector.java:196)
    at com.android.okhttp.internal.http.RouteSelector.nextProxy(RouteSelector.java:144)
    at com.android.okhttp.internal.http.RouteSelector.next(RouteSelector.java:89)
    at com.android.okhttp.internal.http.StreamAllocation.findConnection(StreamAllocation.java:190)
    at com.android.okhttp.internal.http.StreamAllocation.findHealthyConnection(StreamAllocation.java:142)
    at com.android.okhttp.internal.http.StreamAllocation.newStream(StreamAllocation.java:104)
    at com.android.okhttp.internal.http.HttpEngine.connect(HttpEngine.java:392)
    at com.android.okhttp.internal.http.HttpEngine.sendRequest(HttpEngine.java:325)
    at com.android.okhttp.internal.huc.HttpURLConnectionImpl.execute(HttpURLConnectionImpl.java:488)
    at com.android.okhttp.internal.huc.HttpURLConnectionImpl.getResponse(HttpURLConnectionImpl.java:434)
    at com.android.okhttp.internal.huc.HttpURLConnectionImpl.getResponseCode(HttpURLConnectionImpl.java:565)
    at com.android.okhttp.internal.huc.DelegatingHttpsURLConnection.getResponseCode(DelegatingHttpsURLConnection.java:105)
    at com.android.okhttp.internal.huc.HttpsURLConnectionImpl.getResponseCode(HttpsURLConnectionImpl.java:26)
    at com.algolia.search.saas.AbstractClient._requestRaw(AbstractClient.java:616)
    at com.algolia.search.saas.AbstractClient._request(AbstractClient.java:504)
    at com.algolia.search.saas.AbstractClient.deleteRequest(AbstractClient.java:417)
    at com.algolia.search.saas.Index.deleteObject(Index.java:1245)
    at sk.upjs.ics.android.teazoneinc.Adapters.AlgoliaSearchAdapter.deleteObject(AlgoliaSearchAdapter.java:122)
    at sk.upjs.ics.android.teazoneinc.Dialogs.DialogOdstranitUcet$onCreateDialog$1$1.onEvent(DialogOdstranitUcet.kt:43)
    at sk.upjs.ics.android.teazoneinc.Dialogs.DialogOdstranitUcet$onCreateDialog$1$1.onEvent(DialogOdstranitUcet.kt:23)
    at sk.upjs.ics.android.teazoneinc.Adapters.Firebase.authentication.AuthAdapter$reauthenticate$1.onSuccess(AuthAdapter.kt:74)
    at sk.upjs.ics.android.teazoneinc.Adapters.Firebase.authentication.AuthAdapter$reauthenticate$1.onSuccess(AuthAdapter.kt:16)
    at com.google.android.gms.tasks.zzn.run(Unknown Source:4)
    at android.os.Handler.handleCallback(Handler.java:873)
    at android.os.Handler.dispatchMessage(Handler.java:99)
    at android.os.Looper.loop(Looper.java:214)
    at android.app.ActivityThread.main(ActivityThread.java:7063)
    at java.lang.reflect.Method.invoke(Native Method)
    at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:494)
    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:965)

Thanks for every response.

Hello @tynky552,

The issue that you are having is related to the following StackOverflow thread.

On another note, you can also use the Kotlin API Client that we have released last year.

Thanks!

1 Like