【问题标题】:Android App works in Debug Mode, but not in Run modeAndroid App 在调试模式下工作,但不在运行模式下
【发布时间】:2015-10-10 12:20:08
【问题描述】:

我已经处理过之前提出的类似问题,但稀缺的回答没有帮助。 我正在使用 Volley 库在 Recycler 视图中填充 JSON。 这是日志猫: 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

【问题讨论】:

    标签: android android-recyclerview android-volley


    【解决方案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() 方法中为您的列表视图设置适配器。

    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();
                    }
                }
    

    【讨论】:

    • 先检查logcat,只有在收到响应时才设置适配器,或者在适配器上做notifyDataseChanged()。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-12-09
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多