How to fix Expected BEGIN_OBJECT in Retrofit? - java

In my application i want use Retrofit for get some data from server.
I write below codes but when run application and call api show me below error :
E/socketLogResponse: Err : com.google.gson.JsonSyntaxException: java.lang.IllegalStateException: Expected BEGIN_OBJECT but was STRING at line 1 column 1 path $
Please see my above codes and help me
API response from server :
{
"status": "ok",
"time": 0.014972925186157227
}
ApiService interface :
#POST("api/log")
Call<SocketPingResponse> getSocketPingLog(#Header("jwt") String jwt, #Body SocketPingBodySendData socketPingBodySendData);
SocketPingResponse class :
public class SocketPingResponse {
#SerializedName("status")
#Expose
private String status;
#SerializedName("time")
#Expose
private Double time;
public String getStatus() {
return status;
}
public void setStatus(String status) {
this.status = status;
}
public Double getTime() {
return time;
}
public void setTime(Double time) {
this.time = time;
}
}
SocketPingBodySendData class :
public class SocketPingBodySendData {
#SerializedName("auction_id")
#Expose
int auction_id;
#SerializedName("data")
#Expose
List<SocketPingEntity> data;
public int getAuction_id() {
return auction_id;
}
public void setAuction_id(int auction_id) {
this.auction_id = auction_id;
}
public List<SocketPingEntity> getData() {
return data;
}
public void setData(List<SocketPingEntity> data) {
this.data = data;
}
}
Api call codes in activity :
pingEntityList.addAll(socketPingDatabase.socketPingDao().getSocketPingEntityList());
SocketPingBodySendData pingBodySendData = new SocketPingBodySendData();
pingBodySendData.setAuction_id(auctionID);
pingBodySendData.setData(pingEntityList);
Toast.makeText(context, ""+pingEntityList.size(), Toast.LENGTH_SHORT).show();
Call<SocketPingResponse> pingResponseCall = apis.getSocketPingLog(jwtToken, pingBodySendData);
pingResponseCall.enqueue(new Callback<SocketPingResponse>() {
#Override
public void onResponse(Call<SocketPingResponse> call, Response<SocketPingResponse> response) {
if (response.body() != null) {
Toast.makeText(context, response.body().getStatus(), Toast.LENGTH_SHORT).show();
if (response.body().getStatus().equals("ok")) {
pingEntityList.clear();
socketPingDatabase.socketPingDao().deleteAll();
}
}
}
#Override
public void onFailure(Call<SocketPingResponse> call, Throwable t) {
Log.e("socketLogResponse", "Err : " + t.toString());
}
});
How can i fix this issue?

You need to add a gsonconverter factory before building your api service interface.
Retrofit retrofit = new Retrofit.Builder()
.baseUrl(BASE_URL)
.addConverterFactory(GsonConverterFactory.create())
.build();
retrofit.create(apiservice.class)

Related

Access to Return value in Response Body from Retrofit2 Call

Being new to Retrofit2 and having troubles in processing the Response Body from the Call - the needed Response is visible in the Android Studio Debugger, the data is there; however, due to lack of Java skills,
it is unclear to me how to access the Data that I am receiving. It looks like type conversion is needed.
The data looks like this -
Log.d(TAG, "messageId" + addBookingMessageList.toString());
gives me
messageIdcom.example.xxx.AddBookingMessage#88fe1de
and
Log.d(TAG, "addBookingMessageList Class" + addBookingMessageList.getClass().getName());
returns
addBookingMessageList Classjava.lang.String
How do I parse this data correctly? I know it´s an Object, but it is
unclear to me how to access the object properties.
Any hints or help would be very much appreciated.
Here´s my Retrofit Call:
public static void putBookingOnPallet(String basic,
AddBookingMessage message, Context mContext) {
MessagesApi messageApi = retrofit.create(MessagesApi.class);
//making the call objects
Call<AddBookingMessage> call = messageApi.addBooking(basic, message);
//call.execute();
call.enqueue(new Callback<AddBookingMessage>() {
#Override
public void onResponse(#NonNull Call<AddBookingMessage> call, #NonNull
Response<AddBookingMessage> response) {
if (response.isSuccess()) {
Object addBookingMessageList;
addBookingMessageList = response.body().toString();
Log.d(TAGGG, (String) addBookingMessageList.toString());
Log.d(TAG, "messageId" + addBookingMessageList.toString());
Log.d(TAG, "addBookingMessageList Class" + addBookingMessageList.getClass().getName());
//Toast.makeText(context, statusCode, Toast.LENGTH_LONG).show();
}
else {
int statusCode = response.code();
Log.d(TAG, "statusCode" + statusCode);
}
}
#Override
public void onFailure(Call<AddBookingMessage> call, Throwable t) {
Log.d(TAG, "t.getMessage" + t.getMessage());
Toast.makeText(mContext, t.getMessage(), Toast.LENGTH_LONG).show();
}
});
}
Here´s my MessagesAPI:
import retrofit2.Call;
import retrofit2.http.Body;
import retrofit2.http.Header;
import retrofit2.http.Headers;
import retrofit2.http.POST;
public interface MessagesApi {
String BASE_URL = "xxx";
#POST("message")
#Headers({ "Content-Type: application/json;charset=UTF-8"})
Call<AddBookingMessage> addBooking(
#Header("Authorization")
String basic,
#Body AddBookingMessage message
);
#POST("message")
#Headers({ "Content-Type: application/json;charset=UTF-8"})
Call<AddBookingMessage> removebooking(
#Header("Authorization")
String basic,
#Body AddBookingMessage message
);
}
Here´s my Pojo:
package xxx;
import com.google.gson.annotations.Expose;
import com.google.gson.annotations.SerializedName;
public class AddBookingMessage {
#SerializedName("type")
#Expose
private String type;
#SerializedName("time")
#Expose
private Integer fromID;
#SerializedName("fromID")
#Expose
private Integer toID;
#SerializedName("toID")
#Expose
private Integer typeID;
#SerializedName("typeID")
#Expose
private String title;
#SerializedName("title")
#Expose
private String receiptNo;
#SerializedName("receiptNo")
#Expose
private String note;
#SerializedName("note")
#Expose
/* private String id;
#SerializedName("id")
#Expose*/
private Long time;
public String getType() {
return type;
}
public void setType(String type) {
this.type = type;
}
public void setTitle(String title) {
this.title = title;
}
public void getTitle(String title) {
this.title = title;
}
public Integer getFromId() {
return fromID;
}
public void setFromId(Integer fromID) {
this.fromID = fromID;
}
public Integer getToID() {
return toID;
}
public void setToId(Integer toId) {
this.toID = toId;
}
public Integer getTypeId() {
return typeID;
}
public void setTypeId(Integer typeID) {
this.typeID = typeID;
}
public String getReceiptNo() {
return receiptNo;
}
public void setReceiptNo(String receiptNo) {
this.receiptNo = receiptNo;
}
public String getNote() {
return note;
}
public void setNote(String note) {
this.note = note;
}
public Long getTime() {
return time;
}
public void setTime(long time) {
this.time = time;
}
/*public String getId() {
return id;
}
public void setId(String id) {
this.id = id;
}*/
}
Again, any hints or help would be vey much appreciated as I am stuck here, Thanks in advance!
As #Chirag Rayani mentioned, you should have your pojo in the api definition and in the call. So you should have something like:
MessageApi:
Change
Call<Object> addBooking(headers, etc...);
to
Call<AddBookingMessage> addBooking(headers, etc...);
And same for the call:
Call<AddBookingMessage> call = messageApi.addBooking(basic, message);
call.enqueue(new Callback<AddBookingMessage>() {
#Override
public void onResponse(#NonNull Call<AddBookingMessage> call, #NonNull
Response<AddBookingMessage> response) {
if (response.isSuccess()) {
// use your object here
Log.v("response", "id " + response.body().getId());
...
}
}
#Override
public void onFailure(Call<AddBookingMessage> call, Throwable t) {
...
}
});

Unable to fetch response after login using Retrofit2

I am trying to login user in my app for that I am using retrofit2 for networking But when after entering email and password my app is crashing and showing below logcat error.
java.lang.NullPointerException: Attempt to invoke interface method 'java.lang.Object java.util.List.get(int)' on a null object reference
Below is my code:
Login response is
{
"data": [
{
"email": "digi#gmail.com",
"address": "Hsbdbshbd"
}
],
"status": true,
"code": 200
}
RetrofitClient.java
public class RetrofitClient {
public static Retrofit retrofit = null;
public static Retrofit getInstance(){
OkHttpClient okHttpClient = new OkHttpClient.Builder()
.connectTimeout(22, TimeUnit.SECONDS)
.readTimeout(22, TimeUnit.SECONDS)
.writeTimeout(22, TimeUnit.SECONDS)
.build();
if(retrofit == null)
retrofit = new Retrofit.Builder()
.baseUrl("http://www.gurgaonhomeo.in/api_server/")
.addConverterFactory(GsonConverterFactory.create(new GsonBuilder().setLenient().create()))
.addCallAdapterFactory(RxJava2CallAdapterFactory.create())
.client(okHttpClient)
.build();
return retrofit;
}
}
ApiService.java
#POST("login")
#FormUrlEncoded
Observable<LoginResponse> loginUser(#Field("email") String email,
#Field("password") String password);
LoginResponse.java
public class LoginResponse {
#Expose
#SerializedName("code")
private String code;
#Expose
#SerializedName("data")
private List<LoginRes> data;
#Expose
#SerializedName("status")
private String status;
public String getCode() {
return code;
}
public void setCode(String code) {
this.code = code;
}
public List<LoginRes> getData() {
return data;
}
public void setData(List<LoginRes> data) {
this.data = data;
}
public String getStatus() {
return status;
}
public void setStatus(String status) {
this.status = status;
}
}
LoginRes.java
public class LoginRes {
#SerializedName("address")
private String address;
#SerializedName("email")
private String email;
public String getAddress() {
return address;
}
public void setAddress(String address) {
this.address = address;
}
public String getEmail() {
return email;
}
public void setEmail(String email) {
this.email = email;
}
}
Login.java
private void signIn(String mail, String pwd) {
Retrofit retrofit = RetrofitClient.getInstance();
ApiService apiService = retrofit.create(ApiService.class);
apiService.loginUser(mail,pwd).subscribeOn(Schedulers.io())
.observeOn(AndroidSchedulers.mainThread())
.subscribe(new Observer<LoginResponse>() {
#Override
public void onSubscribe(Disposable d) {
}
#Override
public void onNext(LoginResponse loginResponse) {
prg.dismiss();
List<LoginRes> res = loginResponse.getData();
Toast.makeText(Login.this, "" +res.get(0).getEmail(),
Toast.LENGTH_SHORT).show();
}
#Override
public void onError(Throwable e) {
TastyToast.makeText(getApplicationContext(),e.getMessage(),TastyToast.LENGTH_LONG,
TastyToast.ERROR).show();
prg.dismiss();
}
#Override
public void onComplete() {
}
});
}
Why am I getting this error?
After List<LoginRes> res = loginResponse.getData(); line check for Log.d("TAG", "response: " +res)
Check if the res value is null or not?
Also check here #POST("login") I think in this part "login", there should be an url of login that will be use after base url.

Response is not coming from server using retrofit2

Hi in the below code i have a get method from get method parsing the json response using retrofit library.
For the below challenge class parsing the json response through pojo classes and but response is not coming from server .
can any one please help to resolve this issue
response :
{
success: true,
result: {
token: TOKENSTRING, // Challenge token to be used for login.
serverTime: TIMESTAMP, // Current Server time
expireTime: TIMESTAMP // Time when token expires
}
}
GetChallenge.java:
private void getchallenge() {
//Here a logging interceptor is created
HttpLoggingInterceptor logging = new HttpLoggingInterceptor();
logging.setLevel(HttpLoggingInterceptor.Level.BODY);
//The logging interceptor will be added to the http client
OkHttpClient.Builder httpClient = new OkHttpClient.Builder();
httpClient.addInterceptor(logging);
final GetNoticeDataService service = RetrofitInstance.getRetrofitInstance().create(GetNoticeDataService.class);
/** Call the method with parameter in the interface to get the notice data*/
Call<ManageChallenge> call = service.getChallengeList();
/**Log the URL called*/
Log.wtf("URL Called", call.request().url() + "");
call.enqueue(new Callback<ManageChallenge>() {
#Override
public void onResponse(Call<ManageChallenge> call, Response<ManageChallenge> response) {
if(response.isSuccessful() ) {
ManageChallenge challenge=response.body();
// String response1=response.body().toString();
String success=challenge.getSuccess().toString();
if(success.equals("true")){
String result= challenge.getResult().toString();
try {
JSONObject jsonObject =new JSONObject(result);
String token = jsonObject.getString("token");
Log.i("token", "token" + token);
String serverTime =jsonObject.getString("serverTime");
Log.i("serverTime", "serverTime" + serverTime);
String expireTime =jsonObject.getString("expireTime");
Log.i("expireTime", "expireTime" + expireTime);
} catch (JSONException e) {
e.printStackTrace();
}
}
Log.i("REsult", "Get submitted to API." + challenge);
}
}
#Override
public void onFailure(Call<ManageChallenge> call, Throwable t) {
Toast.makeText(LoginActivity.this, "Something went wrong...Error message: " + t.getMessage(), Toast.LENGTH_SHORT).show();
}
});
}
RetrofitInstance.java:
public class RetrofitInstance {
private static Retrofit retrofit;
private static final String BASE_URL = "http://XXXXXXXXXXXX/";
/**
* Create an instance of Retrofit object
* */
public static Retrofit getRetrofitInstance() {
if (retrofit == null) {
retrofit = new retrofit2.Retrofit.Builder()
.baseUrl(BASE_URL)
.addConverterFactory(GsonConverterFactory.create())
.build();
}
return retrofit;
}
}
GetNoticeDataService.java:
public interface GetNoticeDataService {
#Headers("Content-Type: application/json")
#GET("webservice.php?operation=getchallenge&username=admin")
Call<ManageChallenge> getChallengeList();
}
ManageChallenge.java:
public class ManageChallenge {
#SerializedName("success")
private String success;
#SerializedName("result")
private List <getChallengeList> result;
public String getSuccess() {
return success;
}
public void setSuccess(String success) {
this.success = success;
}
public List<getChallengeList> getResult() {
return result;
}
public void setResult(List<getChallengeList> result) {
this.result = result;
}
}
getChallengeList.java:
public class getChallengeList {
#SerializedName("token")
#Expose
private String token;
#SerializedName("serverTime")
#Expose
private String serverTime;
#SerializedName("expireTime")
#Expose
private String expireTime;
public String getToken() {
return token;
}
public void setToken(String token) {
this.token = token;
}
public String getServerTime() {
return serverTime;
}
public void setServerTime(String serverTime) {
this.serverTime = serverTime;
}
public String getExpireTime() {
return expireTime;
}
public void setExpireTime(String expireTime) {
this.expireTime = expireTime;
}
public getChallengeList(String tokens, String expireTimes, String serverTimes){
token = tokens;
expireTime = expireTimes;
serverTime = serverTimes;
}
}
Postman response:
{"success":true,"result":{"token":"5e2ab99eb318f","serverTime":1579858334,"expireTime":1579858634}}
According to your response, there is no List there for the issue is here
#SerializedName("result")
private List<GetChallengeList> result;
Change it like this
public class ManageChallenge {
#SerializedName("success")
private String success;
#SerializedName("result")
private GetChallengeList result;
public String getSuccess() {
return success;
}
public void setSuccess(String success) {
this.success = success;
}
public GetChallengeList getResult() {
return result;
}
public void setResult(GetChallengeList result) {
this.result = result;
}
}
GetChallengeList class
public class GetChallengeList {
#SerializedName("token")
#Expose
private String token;
#SerializedName("serverTime")
#Expose
private String serverTime;
#SerializedName("expireTime")
#Expose
private String expireTime;
public String getToken() {
return token;
}
public void setToken(String token) {
this.token = token;
}
public String getServerTime() {
return serverTime;
}
public void setServerTime(String serverTime) {
this.serverTime = serverTime;
}
public String getExpireTime() {
return expireTime;
}
public void setExpireTime(String expireTime) {
this.expireTime = expireTime;
}
public GetChallengeList(String tokens, String expireTimes, String serverTimes){
token = tokens;
expireTime = expireTimes;
serverTime = serverTimes;
}
}
In your postman response, "result" return a json object, but in your ManageChallenge.java. You declare result as List of object. So I thinks that it may cause some error when casting.
PS. You should declare your class name with upper case at the 1st character. If not, it's may cause some confuse in the future.
PS2. Sorry for my terrible English skill.
I dont understand this you are using retrofit and getting the response using json object, directly you can pass you model call into retrofit and than easily get the data using the model call . responce.body().challenge().getResult().toString()

How to show a list in Android by using retrofit library?

I have to show A list in an Activity
MY API key is:
http://api.cuidadotechnologies.com/NSSPL/leave_dtls.php
Using GSON converter and retrofit library.
this API throws response in JSON like this
{
"status": 0,
"response_data": [
{
"id": "12",
"uid": "USER00000003",
"reason": "Test",
"type": "Plan Leave",
"SataDate": "2018-09-18",
"EndDate": "2018-09-25",
"ApprovedBy": "USER00000002",
"ApprovedDate": "2018-09-18",
"Status": "REJECTED",
"Remarks": "Test Reject"
},
{
"id": "13",
"uid": "USER00000003",
"reason": "Wedding",
"type": "Plan Leave",
"SataDate": "2018-01-28",
"EndDate": "2018-02-05",
"ApprovedBy": "USER00000002",
"ApprovedDate": "2018-09-18",
"Status": "APPROVED",
"Remarks": "Ok"
}
]
}
I am novice in this method please help me to do this step by step.
Try this way..
make retrofit object..
public class ApiClient {
private final static String BASE_URL = "http://api.cuidadotechnologies.com/NSSPL/";
public static ApiClient apiClient;
private Retrofit retrofit = null;
public static ApiClient getInstance() {
if (apiClient == null) {
apiClient = new ApiClient();
}
return apiClient;
}
//private static Retrofit storeRetrofit = null;
public Retrofit getClient() {
return getClient(null);
}
private Retrofit getClient(final Context context) {
HttpLoggingInterceptor interceptor = new HttpLoggingInterceptor();
interceptor.setLevel(HttpLoggingInterceptor.Level.BODY);
OkHttpClient.Builder client = new OkHttpClient.Builder();
client.readTimeout(60, TimeUnit.SECONDS);
client.writeTimeout(60, TimeUnit.SECONDS);
client.connectTimeout(60, TimeUnit.SECONDS);
client.addInterceptor(interceptor);
client.addInterceptor(new Interceptor() {
#Override
public okhttp3.Response intercept(Chain chain) throws IOException {
Request request = chain.request();
return chain.proceed(request);
}
});
retrofit = new Retrofit.Builder()
.baseUrl(BASE_URL)
.client(client.build())
.addConverterFactory(GsonConverterFactory.create())
.build();
return retrofit;
}
}
make interface for api calling.
public interface ApiInterface {
#GET("leave_dtls.php")
Call<ResponseData> getData();
}
make pojo class for response.
public class ResponseDataItem{
#SerializedName("Status")
private String status;
#SerializedName("uid")
private String uid;
#SerializedName("reason")
private String reason;
#SerializedName("ApprovedDate")
private String approvedDate;
#SerializedName("Remarks")
private String remarks;
#SerializedName("ApprovedBy")
private String approvedBy;
#SerializedName("id")
private String id;
#SerializedName("type")
private String type;
#SerializedName("EndDate")
private String endDate;
#SerializedName("SataDate")
private String sataDate;
public void setStatus(String status){
this.status = status;
}
public String getStatus(){
return status;
}
public void setUid(String uid){
this.uid = uid;
}
public String getUid(){
return uid;
}
public void setReason(String reason){
this.reason = reason;
}
public String getReason(){
return reason;
}
public void setApprovedDate(String approvedDate){
this.approvedDate = approvedDate;
}
public String getApprovedDate(){
return approvedDate;
}
public void setRemarks(String remarks){
this.remarks = remarks;
}
public String getRemarks(){
return remarks;
}
public void setApprovedBy(String approvedBy){
this.approvedBy = approvedBy;
}
public String getApprovedBy(){
return approvedBy;
}
public void setId(String id){
this.id = id;
}
public String getId(){
return id;
}
public void setType(String type){
this.type = type;
}
public String getType(){
return type;
}
public void setEndDate(String endDate){
this.endDate = endDate;
}
public String getEndDate(){
return endDate;
}
public void setSataDate(String sataDate){
this.sataDate = sataDate;
}
public String getSataDate(){
return sataDate;
}
}
final response..
public class ResponseData {
#SerializedName("response_data")
private List<ResponseDataItem> responseData;
#SerializedName("status")
private int status;
public void setResponseData(List<ResponseDataItem> responseData){
this.responseData = responseData;
}
public List<ResponseDataItem> getResponseData(){
return responseData;
}
public void setStatus(int status){
this.status = status;
}
public int getStatus(){
return status;
}
}
called api into fragment or activity like this way..
ApiInterface apiInterface = ApiClient.getInstance().getClient().create(ApiInterface.class);
Call<ResponseData> responseDataCall=apiInterface.getData();
responseDataCall.enqueue(new Callback<ResponseData>() {
#Override
public void onResponse(Call<ResponseData> call, Response<ResponseData> response) {
if (response.isSuccessful() && response.body()!=null && response!=null){
List<ResponseDataItem> data=response.body().getResponseData();
}
}
#Override
public void onFailure(Call<ResponseData> call, Throwable t) {
t.printStackTrace();
}
});
You can use use POJO classes for converting JSON into classes. Use below website to convert JSON to POJO.
http://www.jsonschema2pojo.org
After that you can use Retrofit to call API and get response. Get reference from this site : https://square.github.io/retrofit/
After you convert into classes you can use Gson Methods for conversion.
SomeModelClass responseModel = new Gson().fromJson(response, SomeModelClass.class);
You can use this addConverterFactory(GsonConverterFactory.create()) retrofit method to directly convert response into class model if you don't want to do it manually.
And finally you can Create adapter using ViewHolder Pattern and use that adapter with RecyclerView.

Not able to display the Data using retrofit library

I am new to retrofit my aim is to display the data from a url using the retrofit library.
My Json data is:
`{
"RestResponse": {
"messages": [
"Total [249] records found."
],
"result": [
{
"name": "Afghanistan",
"alpha2_code": "AF",
"alpha3_code": "AFG"
},
{
"name": "��land Islands",
"alpha2_code": "AX",
"alpha3_code": "ALA"
},
{
"name": "Albania",
"alpha2_code": "AL",
"alpha3_code": "ALB"
},
{
"name": "Algeria",
"alpha2_code": "DZ",
"alpha3_code": "DZA"
},`
I would like to display the names of country in the LogCat and here are the gson converted Pojo classes
public class RestResponse {
#SerializedName("messages")
#Expose
private List<String> messages = null;
#SerializedName("result")
#Expose
private List<Result> result = null;
public List<String> getMessages() {
return messages;
}
public void setMessages(List<String> messages) {
this.messages = messages;
}
public List<Result> getResult() {
return result;
}
public void setResult(List<Result> result) {
this.result = result;
}
}
Second one Result.java:
public class Result {
#SerializedName("name")
#Expose
private String name;
#SerializedName("alpha2_code")
#Expose
private String alpha2Code;
#SerializedName("alpha3_code")
#Expose
private String alpha3Code;
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getAlpha2Code() {
return alpha2Code;
}
public void setAlpha2Code(String alpha2Code) {
this.alpha2Code = alpha2Code;
}
public String getAlpha3Code() {
return alpha3Code;
}
public void setAlpha3Code(String alpha3Code) {
this.alpha3Code = alpha3Code;
}
}
and Finally Movies.java //Example.java generated by Gson Converter:
public class Movies {
#SerializedName("RestResponse")
#Expose
private RestResponse restResponse;
public RestResponse getRestResponse() {
return restResponse;
}
public void setRestResponse(RestResponse restResponse) {
this.restResponse = restResponse;
}
}
From the above classes I am trying to retrieve the data. My RetrofitInstance is:
public class RetrofitInstance {
private static Retrofit retrofit = null;
private static String BASE_URL = "http://services.groupkt.com/";
public static ApiEndpoints getCombine() {
if (retrofit == null) {
retrofit = new Retrofit
.Builder()
.baseUrl(BASE_URL)
.addConverterFactory(GsonConverterFactory.create())
.build();
}
return retrofit.create(ApiEndpoints.class);
}
}
and Endpoints Interface is:
public interface ApiEndpoints {
#GET("country/get/all")
Call<Movies> getResults();
}
and In MainActivity is used the following:
ApiEndpoints getCountryDataService= RetrofitInstance.getCombine();
Call<Movies> call=getCountryDataService.getResults();
call.enqueue(new Callback<Movies>() {
#Override
public void onResponse(Call<Movies> call, Response<Movies> response) {
Movies info=response.body();
if(info !=null && info.getRestResponse() != null){
results=(ArrayList<Result>) info.getRestResponse().getResult();
for(Result r:results){
Log.i("testing123","*********************************"+ r.getName());
}
}
}
#Override
public void onFailure(Call<Movies> call, Throwable t) {
Log.i("Error",t.fillInStackTrace()+"s");
t.fillInStackTrace();
}
});
Finally I am not able to print the countries in the Log. I am getting the following Error like
java.net.UnknownServiceException: CLEARTEXT communication to services.groupkt.com not permitted by network security policys
and iam new to retrofit concept.
Please help
Thanks in Advance.
I solved my problem by reducing the gradle version from
classpath 'com.android.tools.build:gradle:3.1.4'
to
classpath 'com.android.tools.build:gradle:3.1.2'

Categories

Resources