K
K
Konstantin Lipatov2018-04-27 17:46:54
Android
Konstantin Lipatov, 2018-04-27 17:46:54

Why does an error occur when sending a GET request via Okhttp?

I have the following code

OkHttpClient client;
Request request = new Request.Builder()
                        .url("http://private-anon-2e719df222-newsapitest.apiary-proxy.com/api/news/football")
                        .build();
                
                Response response = client.newCall(request).execute();

But when sending a client.newCall(request).execute() request, an error occurs:
Attempt to invoke virtual method 'okhttp3.Call okhttp3.OkHttpClient.newCall(okhttp3.Request)' on a null object reference
I understand that for some reason the reason the request was not formed, but I can’t figure out why. Please tell me what could be the reason?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
J
JimmDiGreez, 2018-04-27
@Weys

Because the client is not initialized. This is exactly what is said in the error, and this can be seen from the code below.
I think the link to the documentation will be more complete help in the question of how to initialize it.
https://square.github.io/okhttp/3.x/okhttp/okhttp3...

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question