我尝试使用Volley在回收器视图中获取JSON数据,但我始终会遇到以下错误:RecyclerView:未连接适配器;它没有连接到适配器。跳过布局
我收到第一个日志错误,但没有收到第二个日志错误,所以我猜错误是在json请求中
private void parseJSON() {
String url = "http://api.themoviedb.org/3/movie/popular?api_key=my-api-key";
Log.e("error", "and error");
JsonObjectRequest request = new JsonObjectRequest(Request.Method.GET, url, null,
new Response.Listener<JSONObject>() {
@Override
public void onResponse(JSONObject response) {
try {
Log.e("error", "and error");
JSONArray jsonArray = response.getJSONArray("results");
for(int i = 0; i < jsonArray.length(); i++){
JSONObject result = jsonArray.getJSONObject(i);
String imageUrl = "http://image.tmdb.org/t/p/w185" + result.getString("poster_path");
mMovieList.add(new Movie(imageUrl));
}
mMovieAdapter = new MovieAdapter(MainActivity.this, mMovieList);
mRecyclerView.setAdapter(mMovieAdapter);
} catch (JSONException e) {
e.printStackTrace();
}
}
}, new Response.ErrorListener() {
@Override
public void onErrorResponse(VolleyError error) {
error.printStackTrace();
}
});
mRequestQueue.add(request);
}