2017-03-03 10 views
0

retrofit library를 사용하고 있습니다. 다른 클래스의 특정 ID 값을 가져 오는 클래스를 만들었으므로 해당 ID의 특정 목록을 가져오고 싶지만 onResponse() 메서드에서 오류가 발생했습니다. 나는 json 형식의 우편 배달부에서 목록을 가져 왔는지 확인했는데 ...... 여기가 아닙니다! Retrofit 라이브러리를 사용하여 onResponse 메서드를 처리하는 방법은 무엇입니까?

public class Main2Activity extends AppCompatActivity implements Callback<MailChimpEmailResponse> { 

    public String idReceived; 
    List<MailChimpEmailResponseSecond> emailList = new ArrayList<>(); 
    private RecyclerView recyclerViewSecond; 

    @Override 
    protected void onCreate(Bundle savedInstanceState) { 
     super.onCreate(savedInstanceState); 
     setContentView(R.layout.activity_main2); 

     Call<MailChimpEmailResponse> call = MailChimpAPIClient.getClient().fetchMembers(idReceived,"efb918ee88a3a8a77-us15"); 
     call.enqueue(this); 

    } 
    @Override 
    public void onResponse(Call<MailChimpEmailResponse> call, Response<MailChimpEmailResponse> response) { 
    Log.d("ashu", "null response"); 
     Intent intent = getIntent(); 
     idReceived = intent.getStringExtra("id_value"); 
     Log.d("ashu", "id received is: " + idReceived); 

     MailChimpEmailResponse listResponse = response.body(); 

     for (MailChimpEmailResponseSecond list : listResponse.emailLists) { 

      Log.d("ashu", list.getEmailListName()); 
      this.emailList = listResponse.emailLists; 

     } 

     recyclerViewSecond = (RecyclerView) findViewById(R.id.my_recycler_view_second); 
     LinearLayoutManager linearLayoutManager = new LinearLayoutManager(this); 
     recyclerViewSecond.setLayoutManager(linearLayoutManager); 
     EmailAdapter adapter = new EmailAdapter(this.emailList); 
     recyclerViewSecond.setAdapter(adapter); 
     adapter.notifyDataSetChanged(); 

    } 

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

    } 
} 

내 API 클래스 :

내 JSON
public interface MailChimpApi { 


    @GET("lists") 
    public Call<MailChimpListResponse> fetchLists(@Query("apikey") String apikey, @Query("offset") int offset, @Query("count") int count); 


    @GET("lists/{list_id}/members") 
    public Call<MailChimpEmailResponse> fetchMembers(@Path("list_id") String listId,@Query("apikey") String apikey); 
} 

:

{ 
    "members": [ 
    { 
     "id": "04d80020e78edd86a79eda", 
     "email_address": "[email protected]", 
     "unique_email_id": "784c772918", 
     "email_type": "html", 
     "status": "subscribed", 
     "merge_fields": { 
     "FNAME": "Ashsdjssh", 
     "LNAME": "kudjskjar" 
     }, 

답변

1

내가 다음 줄 대신 onResponse의에서 onCreate 방법에 있어야한다고 생각,

idReceived = intent.getStringExtra("id_value");