第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

接口聲明為 NULL

接口聲明為 NULL

一只萌萌小番薯 2021-09-15 14:44:39
我正在使用 Retrofit HTTP 中間層進行 API 調用。由于 Retrofit 異步工作,我使用一個接口返回 API 響應。但聲明的接口在Retrofit 的 OnResponse()覆蓋方法中顯示為 NULL 。下面是代碼塊,界面public interface OnResponseListener{        void getCountryListResponse(ArrayList<String> list,int responseCode);    }響應            @Override            public void onResponse(Call<List<Country>> call, Response<List<Country>> response) {                Log.d("Response",response.body().toString());                for (Country country: response.body())                {                    Log.d("Country",country.toString());                    Log.d("CommomName",country.getCommonName());                   // Log.d("BLLL",country.getCommonName());                   countryList.add(country.getCommonName());                }                Log.d("Entered","Vikas Entered");              //  Log.d("ResonseListener",mResponseListener.toString());//Here throwing error, mResponseListener is null object                mResponseListener.getCountryListResponse(countryList,response.code());            }接口聲明private  OnResponseListener mResponseListener;我不知道為什么它是 NULL,即使在聲明了 Object(Interface) 之后。任何幫助將不勝感激。
查看完整描述

2 回答

?
米琪卡哇伊

TA貢獻1998條經(jīng)驗 獲得超6個贊

您必須在其中設置值,并從調用它的位置實現(xiàn)它:


創(chuàng)建一個方法:


public void setResponseListener(OnResponseListener mResponseListener){

    this.mResponseListener = mResponseListener;

}

并從您調用此 call.enqueue() 方法的位置調用它,如以下注冊:


    RestClientClassObject.setResponseListener(new OnResponseListener() {

        @Override

        void getCountryListResponse(ArrayList<String> list, int responseCode) {


            //write code you want to do with list


        }


    });


查看完整回答
反對 回復 2021-09-15
  • 2 回答
  • 0 關注
  • 188 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網(wǎng)微信公眾號