有 Java 编程相关的问题?

你可以在下面搜索框中键入要查询的问题!

使用截取时出现java错误:RecyclerView:未连接适配器;跳过布局

我尝试使用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);
}

共 (0) 个答案