我正在使用改造库。我创建了一个类,其中我从其他类中获取特定id的值,并且我想获取该id的特定列表但是在onResponse()
方法中我得到了一个错误。我以json格式检查邮递员列表正在取样......但不在这里!
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课程:
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);
}
我的json:
{
"members": [
{
"id": "04d80020e78edd86a79eda",
"email_address": "ashuingh.02046547@gmail.com",
"unique_email_id": "784c772918",
"email_type": "html",
"status": "subscribed",
"merge_fields": {
"FNAME": "Ashsdjssh",
"LNAME": "kudjskjar"
},
答案 0 :(得分:0)
我认为以下行应该在onCreate方法而不是onResponse,
idReceived = intent.getStringExtra("id_value");