A
A
Alexander Nikulshin2020-09-28 21:41:17
Android
Alexander Nikulshin, 2020-09-28 21:41:17

Why is there no HTTP request to the server from the ListFragment class descendant?

There is an inheritor of the ListFragment class, which, when accessed, will create a request to the server and then build a list on the screen. But for some reason I have an empty list displayed on the screen.
I decided to check if the request to the server is happening and added the information to the log. But as it turned out, the application does not even send a request to the server. This happens for the ListFragment heir, in MainActivity a request to the server is sent and successfully arrives.

public class SingleListFragment extends ListFragment {
ArrayList<Order> OrderList;
@Override
    public void onViewCreated(View view, Bundle bundle){
        super.onViewCreated(view,bundle);
        final MyListAdapter myListAdapter = new MyListAdapter(getActivity(),
                R.layout.order_list_item, OrderList);
        JsonArrayRequest jsObjRequest = new JsonArrayRequest(Request.Method.GET, "http://192.168.1.200:5000/TerminalCommon/GetOrders?idStep=24", null, new Response.Listener<JSONArray>() {
            @Override
            public void onResponse(JSONArray response) {
                try {
                    Log.d("Запрос на сервер","получен");
                    GsonBuilder builder=new GsonBuilder();
                    Gson gson=builder.create();
                    ArrayList<Order> orderList=gson.fromJson(response.toString(),new TypeToken<List<Order>>(){}.getType());
                    OrderList=orderList;
                    myListAdapter.notifyDataSetChanged();
                }
                catch (Exception e){
                    Log.e("Get steps",e.getMessage());
                };
            }
        }, new Response.ErrorListener() {
            @Override
            public void onErrorResponse(VolleyError error) {
                Log.e("Error gson",error.getMessage());
            }
        });
        RequestQueue queue = Volley.newRequestQueue(getActivity().getApplicationContext());
        queue.add(jsObjRequest);
        setListAdapter(myListAdapter);
    }
}


There is a feeling that I made a mistake somewhere in this line:
RequestQueue queue = Volley.newRequestQueue(getActivity().getApplicationContext());

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Alexander Nikulshin, 2020-09-29
@xasya89

I figured it out, I forgot to specify in the manifest:

<uses-permission android:name="android.permission.INTERNET" />

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question