onResponse(JSONObject响应)不起作用

时间:2016-12-30 12:52:13

标签: android textview

我试图在TextView result;

中显示我的数据库中的记录

但我发现public void onResponse(JSONObject response)没有执行。 Textview中不显示任何记录。我在这里做错了什么?

public class LoginActivity extends AppCompatActivity {
    EditText firstname, lastname, age;
    Button show;
    TextView result;
    RequestQueue requestQueue;


   protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_login);

        firstname = (EditText) findViewById(R.id.editText);
        lastname = (EditText) findViewById(R.id.editText2);
        age = (EditText) findViewById(R.id.editText3);

        show = (Button) findViewById(R.id.button2);
        result = (TextView) findViewById(R.id.textView);

        requestQueue = Volley.newRequestQueue(getApplicationContext());

        show.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {

                    JsonObjectRequest jsonObjectRequest = new JsonObjectRequest(Request.Method.POST, showUrl, new Response.Listener<JSONObject>(){

                        @Override
                        public void onResponse(JSONObject response) {
                            try {

                                JSONArray students = response.getJSONArray("students");
                                for (int i = 0; i < students.length(); i++){
                                    JSONObject student = students.getJSONObject(i);

                                    String firstname = student.getString("firstname");
                                    String lastname = student.getString("lastname");
                                    String age = student.getString("age");

                                    result.append(firstname + " " + lastname + " " + age + "\n");
                                }
                                result.append("....\n");

                            } catch (JSONException e) {
                                e.printStackTrace();
                            }
                        }
                    }, new Response.ErrorListener(){
                        @Override
                        public void onErrorResponse(VolleyError error) {
                        }
                    });

                    requestQueue.add(jsonObjectRequest);
                }
            });
}
}

我收到此错误消息

  

12-30 18:22:12.420 26346-26346 / com.example.mememe.loginregister   E / Volley:com.android.volley.NoConnectionError:   java.net.ConnectException:无法连接到/127.0.0.1(端口80)   2500ms后:isConnected失败:ECONNREFUSED(拒绝连接)

0 个答案:

没有答案