2017-10-16 4 views
-3

Retrofit에서 로깅 인터셉터를 사용하여 응답을받을 수 있지만 내 onResponse가 호출되지 않습니다.onResponse가 호출되지 않음 Retrofit

내가 사용하는 두 개의 모델 클래스가 아래에 나와 있으며 두 개의 Result 및 JobTitle이라는 이름이 추가로 있습니다.

콜백의 코드는 다음과 같습니다

public class Data { 

@SerializedName("messages") 
@Expose 
private List<Object> messages = null; 
@SerializedName("result") 
@Expose 
private Result result; 

public List<Object> getMessages() { 
    return messages; 
} 

public void setMessages(List<Object> messages) { 
    this.messages = messages; 
} 

public Result getResult() { 
    return result; 
} 

public void setResult(Result result) { 
    this.result = result; 
} 
} 

MainResponse.class

public class MainResponse { 

@SerializedName("status") 
@Expose 
private String status; 
@SerializedName("data") 
@Expose 
private Data data; 

public String getStatus() { 
    return status; 
} 

public void setStatus(String status) { 
    this.status = status; 
} 

public Data getData() { 
    return data; 
} 

public void setData(Data data) { 
    this.data = data; 
} 
} 

Data.class :

Call<MainResponse> call = imsClient.fetchStatus(userCredentials); 
    call.enqueue(new Callback<MainResponse>() { 
     @Override 
     public void onResponse(Call<MainResponse> call, Response<MainResponse> response) { 
      Log.e("Ei", "In response"); 
      MainResponse mainResponse = response.body(); 
      Data data = mainResponse.getData(); 
      Result result = data.getResult(); 
      Toast.makeText(PrimaryLogin.this, "Welcome" + result.getFirstName() + result.getLastName(), Toast.LENGTH_SHORT).show(); 
     } 

     @Override 
     public void onFailure(Call<MainResponse> call, Throwable t) { 


     } 
    }); 

콜백은 실패에 호출되는하지만, 아니 성공적인 호출이 실행되면 문제가 발생합니다. 나는 그것을 이해할 수 없으며 어떤 도움을 주시면 감사하겠습니다.

로그 :

{"status":"success","data":{"messages":[],"result":{"clinicCode":"Medics","firstName":"Charles","lastName":"Sanders","officeId":0,"id":7834,"startDate":1508142509926,"timeZoneId":0,"userDetailId":6,"userName":"charles","jobTitle":{"id":1,"text":"Doctor","count":1},"isSuperUser":false,"clientId":10,"token":"eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJjbGluaWNDb2RlIjoiTWVkaWNzIiwiZW1haWwiOm51bGwsImVuZERhdGUiOm51bGwsImZpcnN0TmFtZSI6IkNoYXJsZXMiLCJsYXN0TmFtZSI6IlNhbmRlcnMiLCJvZmZpY2VJZCI6MCwiaWQiOjc4MzQsInNwZWNpYWx0eUlkIjpudWxsLCJzdGFydERhdGUiOjAsInRpbWVab25lSWQiOjAsInVzZXJEZXRhaWxJZCI6NiwidXNlck5hbWUiOiJjaGFybGVzIiwib2ZmaWNlIjpudWxsLCJzcGVjaWFsdHkiOm51bGwsInRpbWVab25lIjpudWxsLCJ1c2VyRGV0YWlsIjpudWxsLCJwYXJhbWV0ZXJzIjpudWxsLCJqb2JUaXRsZSI6bnVsbCwiaXNTdXBlclVzZXIiOmZhbHNlLCJjbGllbnRJZCI6MTAsImNvZGUiOm51bGwsInRva2VuIjpudWxsLCJlbXBsb3llZUlkIjoxNCwicHJvdmlkZXJJZCI6bnVsbCwiaXNBY3RpdmUiOmZhbHNlLCJpc0xvY2tlZCI6ZmFsc2UsImxhc3RQYXNzd29yZENoYW5nZWQiOjAsImxvY2tlZENvZGVJZCI6bnVsbCwibG9ja2VkRGF0ZVRpbWUiOm51bGwsInBhc3N3b3JkIjpudWxsLCJwYXRpZW50SWQiOm51bGwsInByZWZMYW5nSWQiOm51bGwsInNlc3Npb25JZCI6NzgzNCwiY3JlYXRlZEJ5IjpudWxsLCJlbXBsb3llZSI6bnVsbCwibGFzdE1vZGlmaWVkQnkiOm51bGwsImxvY2tlZENvZGUiOm51bGwsInBhdGllbnQiOm51bGwsInByZWZMYW5nIjpudWxsLCJhcHBsaWNhdGlvbk5hbWUiOm51bGwsIm1hY2hpbmVJZCI6bnVsbCwibGFuZ0lkIjpudWxsLCJjb3VudHJ5Q29kZSI6IlVTIn0.B-C9YWEHWQJue83TnGUa3dnmQYz0ngdNPUqH_6AG8tU","employeeId":14,"isActive":false,"isLocked":false,"lastPasswordChanged":0,"sessionId":0}}} 
+0

응답에 유효한 HTTP 상태가 확실합니까? [로깅 인터셉터] (https://github.com/square/okhttp/tree/master/okhttp-logging-interceptor)를 추가하면 어떻게됩니까? – thepoosh

+0

질문에 로그인을 추가했습니다 –

+0

구문 분석 오류가 발생하여 'onFailure'방법으로 로그인 할 수 있습니다 –

답변

0

가 나는 문제가있어. Result 모델에서, 나는 데이터를 Integer로 저장하고 있었고 응답은 오랫동안 오류가 발생했기 때문에 발생했다.