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

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

使用改造從 api 獲取響應(yīng)以在 recycleview 中獲取響應(yīng)時出錯

使用改造從 api 獲取響應(yīng)以在 recycleview 中獲取響應(yīng)時出錯

縹緲止盈 2021-11-17 15:40:39
我正在嘗試使用此 api 聯(lián)網(wǎng):https : //api.jikan.moe/v3/schedule所以我通過創(chuàng)建 ApiClient.java 類來使用改造,這是它的代碼:public class ApiClient {public static final String BASE_URL = "http://api.themoviedb.org/3/";private static Retrofit retrofit = null;public static Retrofit getClient() {    if (retrofit==null) {        retrofit = new Retrofit.Builder()                .baseUrl(BASE_URL)                .addConverterFactory(GsonConverterFactory.create())                .build();    }    return retrofit;}}完整的鏈接端點(diǎn)的接口是這樣的:public interface ApiInterface {    @GET("schedule")    Call<MainResponse> getSchedule();}所以我在建模數(shù)據(jù)中使用了可序列化,并創(chuàng)建了 MainResponse.java 類來獲取 api 中的主要 monday 數(shù)組:公共類 MainResponse {@SerializedName("monday")private List<Schedule> monday;public List<Schedule> getMonday() {    return monday;}public void setMonday(List<Schedule> monday) {    this.monday = monday;}}然后我創(chuàng)建一個新的建模類來獲取類 Schedule.java 中 monday 數(shù)組的對象項列表:public class Schedule {    @SerializedName("title")    private String title;    public Schedule(String title) {        this.title = title;    }    public String getTitle() {        return title;    }    public void setTitle(String title) {        this.title = title;    }}最后在 MainActivity 我稱之為:final RecyclerView recyclerView = (RecyclerView) findViewById(R.id.schedule_recycler_view);        recyclerView.setLayoutManager(new LinearLayoutManager(this));        ApiInterface apiService =                ApiClient.getClient().create(ApiInterface.class);        Call<MainResponse> call = apiService.getSchedule();        call.enqueue(new Callback<MainResponse>() {正如你所看到的,我使用了一個 recycleview 來獲取 monday 數(shù)組的標(biāo)題,但問題是當(dāng)我運(yùn)行應(yīng)用程序時,它只是因為這個而崩潰:嘗試在空對象引用上調(diào)用虛擬方法“java.util.List com.example.user_pc.capstonestage2.MainResponse.getMonday()”
查看完整描述

2 回答

?
FFIVE

TA貢獻(xiàn)1797條經(jīng)驗 獲得超6個贊

您已聲明錯誤的 API URL 是:


public static final String BASE_URL = "https://api.jikan.moe/v3/";

你MainResponse應(yīng)該是這樣的:


public class MainResponse {


@SerializedName("request_hash")

@Expose

private String requestHash;

@SerializedName("request_cached")

@Expose

private Boolean requestCached;

@SerializedName("request_cache_expiry")

@Expose

private Integer requestCacheExpiry;

@SerializedName("monday")

@Expose

private List<Monday> monday = null;


public String getRequestHash() {

return requestHash;

}


public void setRequestHash(String requestHash) {

this.requestHash = requestHash;

}


public Boolean getRequestCached() {

return requestCached;

}


public void setRequestCached(Boolean requestCached) {

this.requestCached = requestCached;

}


public Integer getRequestCacheExpiry() {

return requestCacheExpiry;

}


public void setRequestCacheExpiry(Integer requestCacheExpiry) {

this.requestCacheExpiry = requestCacheExpiry;

}


public List<Monday> getMonday() {

return monday;

}


public void setMonday(List<Monday> monday) {

this.monday = monday;

}


}

該Genre班


public class Genre {


@SerializedName("mal_id")

@Expose

private Integer malId;

@SerializedName("type")

@Expose

private String type;

@SerializedName("name")

@Expose

private String name;

@SerializedName("url")

@Expose

private String url;


public Integer getMalId() {

return malId;

}


public void setMalId(Integer malId) {

this.malId = malId;

}


public String getType() {

return type;

}


public void setType(String type) {

this.type = type;

}


public String getName() {

return name;

}


public void setName(String name) {

this.name = name;

}


public String getUrl() {

return url;

}


public void setUrl(String url) {

this.url = url;

}


}

最后是Monday班級


public class Monday {


@SerializedName("mal_id")

@Expose

private Integer malId;

@SerializedName("url")

@Expose

private String url;

@SerializedName("title")

@Expose

private String title;

@SerializedName("image_url")

@Expose

private String imageUrl;

@SerializedName("synopsis")

@Expose

private String synopsis;

@SerializedName("type")

@Expose

private String type;

@SerializedName("airing_start")

@Expose

private String airingStart;

@SerializedName("episodes")

@Expose

private Integer episodes;

@SerializedName("members")

@Expose

private Integer members;

@SerializedName("genres")

@Expose

private List<Genre> genres = null;

@SerializedName("source")

@Expose

private String source;

@SerializedName("producers")

@Expose

private List<Object> producers = null;

@SerializedName("score")

@Expose

private Object score;

@SerializedName("licensors")

@Expose

private List<Object> licensors = null;

@SerializedName("r18")

@Expose

private Boolean r18;

@SerializedName("kids")

@Expose

private Boolean kids;


public Integer getMalId() {

return malId;

}


public void setMalId(Integer malId) {

this.malId = malId;

}


public String getUrl() {

return url;

}


public void setUrl(String url) {

this.url = url;

}


public String getTitle() {

return title;

}


public void setTitle(String title) {

this.title = title;

}


public String getImageUrl() {

return imageUrl;

}


public void setImageUrl(String imageUrl) {

this.imageUrl = imageUrl;

}


public String getSynopsis() {

return synopsis;

}


public void setSynopsis(String synopsis) {

this.synopsis = synopsis;

}


public String getType() {

return type;

}


public void setType(String type) {

this.type = type;

}


public String getAiringStart() {

return airingStart;

}


public void setAiringStart(String airingStart) {

this.airingStart = airingStart;

}


public Integer getEpisodes() {

return episodes;

}


public void setEpisodes(Integer episodes) {

this.episodes = episodes;

}


public Integer getMembers() {

return members;

}


public void setMembers(Integer members) {

this.members = members;

}


public List<Genre> getGenres() {

return genres;

}


public void setGenres(List<Genre> genres) {

this.genres = genres;

}


public String getSource() {

return source;

}


public void setSource(String source) {

this.source = source;

}


public List<Object> getProducers() {

return producers;

}


public void setProducers(List<Object> producers) {

this.producers = producers;

}


public Object getScore() {

return score;

}


public void setScore(Object score) {

this.score = score;

}


public List<Object> getLicensors() {

return licensors;

}


public void setLicensors(List<Object> licensors) {

this.licensors = licensors;

}


public Boolean getR18() {

return r18;

}


public void setR18(Boolean r18) {

this.r18 = r18;

}


public Boolean getKids() {

return kids;

}


public void setKids(Boolean kids) {

this.kids = kids;

}


}



查看完整回答
反對 回復(fù) 2021-11-17
?
qq_花開花謝_0

TA貢獻(xiàn)1835條經(jīng)驗 獲得超7個贊

您的 api 鏈接是https://api.jikan.moe/v3/schedule 但在您編寫的代碼中


public static final String BASE_URL = "http://api.themoviedb.org/3/";

您可以將基本 url 更改為https://api.jikan.moe/v3/,或者

在 getSchedule() 的 GET 注釋上提供完整的 url


 @GET("https://api.jikan.moe/v3/schedule")

 Call<MainResponse> getSchedule();


查看完整回答
反對 回復(fù) 2021-11-17
  • 2 回答
  • 0 關(guān)注
  • 184 瀏覽

添加回答

舉報

0/150
提交
取消
微信客服

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

幫助反饋 APP下載

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

公眾號

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