我似乎无法弄清楚为什么以及如何解决这个错误,我正在上网:
MovieItem item = new MovieItem();
它说MovieItem中的MovieItem()无法应用于:
预期参数:id:字符串,标题:字符串,overView:字符串,releaseDate:字符串,等级:字符串,posterPath:字符串,url:字符串。
实际参数:。
private ArrayList<MovieItem> getMovieJsonObject(String movieJSONObject) throws JSONException {
final String m_Result = "results";
final String m_ID = "id";
final String m_Title = "title";
final String m_Release = "release_date";
final String m_Vote = "vote_average";
final String m_Overview = "overview";
final String m_Poster = "poster_path";
ArrayList<MovieItem> movieItems = new ArrayList<>();
JSONObject movieJSON = new JSONObject(movieJSONObject);
JSONArray movieInformation = movieJSON.getJSONArray(m_Result);
for (int i = 0; i < movieInformation.length(); i++) {
MovieItem item = new MovieItem();
JSONObject result_movie = movieInformation.getJSONObject(i);
movieId[i] = result_movie.getString(m_ID);
movieTitle[i] = result_movie.getString(m_Title);
moviePath[i] = result_movie.getString(m_Poster);
moviePlot[i] = result_movie.getString(m_Overview);
movieRating[i] = result_movie.getString(m_Vote);
movieReleaseDate[i] = result_movie.getString(m_Release);
movieItems.add(item);
}
return movieItems;
}
public class MovieItem {
private String id;
private String title;
private String overView;
private String releaseDate;
private String rating;
private String posterPath;
private String url;
public MovieItem(String id, String title, String overView, String releaseDate, String rating, String posterPath, String url) {
this.id = id;
this.title = title;
this.overView = overView;
this.releaseDate = releaseDate;
this.rating = rating;
this.posterPath = posterPath;
this.url = url;
}
public String getId() {
return id;
}
public void setId(String id) {
this.id = id;
}
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 getOverView() {
return overView;
}
public void setOverView(String overView) {
this.overView = overView;
}
public String getReleaseDate() {
return releaseDate;
}
public void setReleaseDate(String releaseDate) {
this.releaseDate = releaseDate;
}
public String getRating() {
return rating;
}
public void setRating(String rating) {
this.rating = rating;
}
public String getPosterPath() {
return posterPath;
}
public void setPosterPath(String posterPath) {
this.posterPath = posterPath;
}
最佳答案
使用您的构造函数:
JSONObject result_movie = movieInformation.getJSONObject(i);
MovieItem item = new MovieItem(result_movie.getString(m_ID),
result_movie.getString(m_Title),
result_movie.getString(m_Overview),
result_movie.getString(m_Release),
result_movie.getString(m_Vote),
result_movie.getString(m_Poster),
"url"
);
movieItems.add(item);