Android App在调试模式下工作,但在运行模式下不工作

时间:2015-10-10 12:20:08

标签: android android-recyclerview android-volley

我已经完成了之前提出的类似问题,但是稀缺的回答没有帮助。 我正在使用Volley Library在Recycler View中填充JSON。 这是logcat: Referring to other SO questions, I have found Failed to set EGL_SWAP_BEHAVIOR on surface 0xb3ffe0e0, error=EGL_SUCCESS is not a problem.

以下是Android Studio项目 - https://github.com/sanke-t/Legistify

1 个答案:

答案 0 :(得分:1)

我在github上看到了你的代码。

JsonArrayRequest fetch = new JsonArrayRequest(Request.Method.GET, url1.toString(), null, new Response.Listener<JSONArray>() {
                    @Override
                    public void onResponse(JSONArray response) {
                        try {
                            for (int i=0;i<response.length();i++)
                            {
                                JSONObject random = response.getJSONObject(i);
                                Lawyer l=new Lawyer();
                                l.setName(random.getString("name"));
                                l.setAddress(random.getString("addr"));
                                l.setPhone(random.getString("phonenum"));
                                l.setField(random.getString("lawfield"));
                                List.add(l);
                            }

                        } catch (Exception e) {
                            e.printStackTrace();
                        }
                    }
                }, new Response.ErrorListener() {

                    @Override
                    public void onErrorResponse(VolleyError error) {
                        error.printStackTrace();
                    }
                });
                queue.add(fetch);
                r=(RecyclerView)findViewById(R.id.rv);
                r.setLayoutManager(new LinearLayoutManager(this));
                adapter=new Adapter(getApplicationContext(),List);
                r.setAdapter(adapter);

您是否尝试在JsonArrayRequest内的onResponse()方法内为listview设置适配器。

public void onResponse(JSONArray response) {
                try {
                    for (int i=0;i<response.length();i++)
                    {
                        JSONObject random = response.getJSONObject(i);
                        Lawyer l=new Lawyer();
                        l.setName(random.getString("name"));
                        l.setAddress(random.getString("addr"));
                        l.setPhone(random.getString("phonenum"));
                        l.setField(random.getString("lawfield"));
                        List.add(l);
                    }
                    r=(RecyclerView)findViewById(R.id.rv);
        r.setLayoutManager(new LinearLayoutManager(this));
        adapter=new Adapter(getApplicationContext(),List);
        r.setAdapter(adapter);
                } catch (Exception e) {
                    e.printStackTrace();
                }
            }