문제가 발생했습니다. 발리와 함께 GET 요청을 사용하고 JSON에서 객체를 생성합니다. 나는 그것을 onclick 청취자 내부에서 작업하도록 만들었지 만, 생성자가 응답을받는 방법에 대한 단서가 없습니다.JSON (발리 요청)에서 객체 생성 Java
이, 이것은 좋은 구현 열린 영화 데이터베이스에서
public class Media extends MainActivity{
private String title;
private String yearReleased;
private String rated;
private String director;
private String actors;
private String plot;
private String posterUrl;
private String type;
final String TAG = AppController.class.getSimpleName();
public Media(String title, String yearReleased, String rated, String director, String actors, String plot, String posterUrl, String type) {
JsonObjectRequest jsonObjectRequest = new JsonObjectRequest(Request.Method.POST, url, null,
new Response.Listener<JSONObject>() {
@Override
public void onResponse(JSONObject response) {
Log.d(TAG, response.toString());
try {
title =
rated = response.getString("Year");
//String rated = response.getString("Rated");
//String released = response.getString("Released");
//String genre = response.getString("Genre");
//String director = response.getString("Director");
//String actors = response.getString("Actors");
//String plot = response.getString("Plot");
//String language = response.getString("Language");
//String awards = response.getString("Awards");
//String poster = response.getString("Title");
//String imdbRating = response.getString("imdbRating");
//String type = response.getString("Type");
} catch (JSONException e) {
e.printStackTrace();
Toast.makeText(getApplicationContext(),
"Error: " + e.getMessage(),
Toast.LENGTH_LONG).show();
}
}
},
new Response.ErrorListener() {
@Override
public void onErrorResponse(VolleyError error) {
VolleyLog.d(TAG, "Error: " + error.getMessage());
Toast.makeText(getApplicationContext(),
error.getMessage(), Toast.LENGTH_SHORT).show();
}
}
);
AppController.getInstance().addToRequestQueue(jsonObjectRequest);
this.title = title;
this.yearReleased = yearReleased;
this.rated = rated;
this.director = director;
this.actors = actors;
this.plot = plot;
this.posterUrl = posterUrl;
this.type = type;
}
public Media(View.OnClickListener mainActivity) {
super();
}
public void getJsonObject() {
}
//@Override
//public String getTitle() {return title;}
public void setTitle(String title) {
this.title = title;
}
public String getYearReleased() {
return yearReleased;
}
public void setYearReleased(String yearReleased) {
this.yearReleased = yearReleased;
}
public String getRated() {
return rated;
}
public void setRated(String rated) {
this.rated = rated;
}
public String getDirector() {
return director;
}
public void setDirector(String director) {
this.director = director;
}
public String getActors() {
return actors;
}
public void setActors(String actors) {
this.actors = actors;
}
public String getPlot() {
return plot;
}
public void setPlot(String plot) {
this.plot = plot;
}
public String getPosterUrl() {
return posterUrl;
}
public void setPosterUrl(String posterUrl) {
this.posterUrl = posterUrl;
}
public String getType() {
return type;
}
public void setType(String type) {
this.type = type;
}
}
또 다른 질문을 URL을 얻을 것이다 내 미디어 클래스이다? 아니면 더 빠르고 더 좋은 방법이 있습니까?