Martin
Martin

Reputation: 429

okhttp3 fail to request for android project

I am using okhttp, for my Android project. All the requirements work good but when I need to call a request for a client it will show the error below:

> The method newCall(Request) is undefined for the type OkHttpClient

I need to create a call like this:

Call call = client.newCall(request);

Upvotes: 1

Views: 2110

Answers (2)

piotrek1543
piotrek1543

Reputation: 19351

Please check which version of OkHttpClient are you already using. As Jake Wharton states: newApi() is reserved only for newest 2.x version. Please take a look at: https://github.com/square/okhttp/issues/814

Please upgrade your OkHttpClient to latest version. Put into Gradle file

      compile 'com.squareup.okhttp3:okhttp:3.0.1'

Then, in your activity import:

import okhttp3.Call;
import okhttp3.Callback;
import okhttp3.OkHttpClient;
import okhttp3.Request;
import okhttp3.Response;

Hope it help

Upvotes: 2

Dalija Prasnikar
Dalija Prasnikar

Reputation: 28530

Make sure that you have correct import classes listed, and that you are not mixing old classes with new ones.

import okhttp3.Call;
import okhttp3.Callback;
import okhttp3.OkHttpClient;
import okhttp3.Request;
import okhttp3.Response;

Upvotes: 0

Related Questions