user3149514
user3149514

Reputation: 7

Volley JsonArrayRequest gives me the error com.android.volley.ServerError

I'm struggling several days with an Volley 1.2.1 JsonArrayRequest. I have created on my website a simple php file which echos a JSONArray

<?php
    $array = array(
        array("c1" => "row1col1", "c2" => "row1col2"),
        array("c1" => "row2col1", "c2" => "row2col2")
    );
    header("Accept","application/json");
    header('Content-Type: application/json');
    echo json_encode($array);
?>

When I start this in my webbrowser it returns the correct response. No I have created an Android app which should read this JSONArray. Until now I don't parse the array, I just want to know if the connect is done. But everytime it responds "com.android.volley.ServerError" I've read several articles about wrong url, http>https, NULL value in the parameters etc., but until now it didn't solve the problem. Any help is welcome

This is my java code:

//here code for requestque
        String url = "https://vivendabalou.pt/test_adrd.php";
        TextView tv = findViewById(R.id.tv_test2);
        RequestQueue rq = Volley.newRequestQueue(this);

        JsonArrayRequest jr = new JsonArrayRequest(Request.Method.GET, url, null,
                new Response.Listener<JSONArray>()
                {
                    @Override
                    public void onResponse(JSONArray response)
                    {
                        tv.setText(tv.getText() + "\n0: OK");
                    }
                }, new Response.ErrorListener()
                    {
                        @Override
                        public void onErrorResponse(VolleyError error)
                        {
                            tv.setText(tv.getText() + "\n1: " + error);
                        }
                    });
        tv.setText(tv.getText() + "\nBefore");
        rq.add(jr);
        tv.setText(tv.getText() + "\nAfter");
//end code for requestque

Upvotes: 0

Views: 11

Answers (0)

Related Questions