why ListView does not filled while I am using AsyncTask?

asynctask deprecated
how to use asynctask in android
how to get data from server using asynctask in android
asynctask parameters
asynctask example in android - stack overflow
asynctask cancel
asynctask get
android asynctask alternative

I am writing an app that uses Google book search API , what the app suppose to do is to display a list of books based on a search query that i provide within the app's code as a String, i use an AsyncTask inner class to handle the background work (making HTTP request , JSON formatting ...etc), I also have book costume adapter and book class to get the data from , my problem is the app dose not display any book in the list view .

here's my code:

My Activity:

public class MainActivity extends AppCompatActivity {

    final static String bookUrl = "https://www.googleapis.com/books/v1/volumes?q=android&maxResults=6";
    private BookAdapter bookAdapter;

    private ArrayList<Book> books;

    private ListView list;

    protected void onCreate(Bundle savedInstanceState) {

         list = (ListView) findViewById(R.id.list);
         new BookAsynck().execute(bookUrl);


    private class BookAsynck extends AsyncTask<String, Void, ArrayList<Book>> {
        protected ArrayList<Book> doInBackground(String... strings) {
            books = Utils.fetchBookData(bookUrl);
            return books;

        protected void onPostExecute(ArrayList<Book> books) {
            bookAdapter = new BookAdapter(MainActivity.this, books);


My Util class :

    public class Utils {
    public static final String LOG_TAG = Utils.class.getSimpleName();

    public static ArrayList<Book> fetchBookData(String requestUrl) {

        ArrayList<Book> bookList = new ArrayList<>();

        URL url = CreateURl(requestUrl);
        String json = null;
        try {
            json = makeHttpRequest(url);
        } catch (IOException e) {
            Log.e(LOG_TAG, "Error closing input stream", e);
        bookList = extractBookData(json);
        return bookList;

    public static URL CreateURl(String stringUrl) {
        URL url = null;
        try {
            url = new URL(stringUrl);
        } catch (MalformedURLException e) {
            Log.e(LOG_TAG, "Error with creating URL ", e);
        return url;

    //make http  request and return a string containing the response
    public static String makeHttpRequest(URL url) throws IOException {
        String jsonResponse = "";
        //if the url is null return empty string
        if (url == null) {
            return jsonResponse;

        HttpURLConnection urlcon = null;
        InputStream inputstream = null;
        try {
            urlcon = (HttpURLConnection) url.openConnection();
            urlcon.setReadTimeout(1000 /*milleseconds*/);
            urlcon.setConnectTimeout(1500 /*milleseconds*/);
//if the request wass Successul (code 200)
            // get the input stream and decode it

            if (urlcon.getResponseCode() == 200) {
                inputstream = urlcon.getInputStream();
                jsonResponse = readFromStream(inputstream);
            } else {
                Log.e(LOG_TAG, "Error response code " + urlcon.getResponseCode());

        } catch (IOException e) {
            Log.e(LOG_TAG, "Problem retrieving the book JSON results", e);
        } finally {
            if (urlcon != null) {
            if (inputstream != null) {

        return jsonResponse;

//decode the inputstream into string that conatin the Jsresponse from the Server

        private static String readFromStream(InputStream inputStream) throws IOException {
            StringBuilder output = new StringBuilder();
            if (inputStream != null) {
                InputStreamReader inputStreamReader = new InputStreamReader(inputStream, Charset.forName("UTF-8"));
                BufferedReader reader = new BufferedReader(inputStreamReader);
                String line = reader.readLine();
                while (line != null) {
                    line = reader.readLine();
            return output.toString();

        public static ArrayList<Book> extractBookData(String json) {
            ArrayList<Book> booklist = new ArrayList<>();

            if (TextUtils.isEmpty(json)) {
                return null;

            try {
                JSONObject base = new JSONObject(json);
                JSONArray itemsArray = base.optJSONArray("items");

                for (int i = 0; i < itemsArray.length(); i++) {
                    JSONObject first = itemsArray.getJSONObject(i);
                    JSONObject volume = new JSONObject("volumeInfo");
                    String title = volume.getString("title");
                    JSONArray authorsArray = volume.getJSONArray("authors");
                    String author = authorsArray.getString(0);

                    Book b = new Book(title, author);

            } catch (JSONException e) {
                Log.e(LOG_TAG, "Problem parsing the book JSON results", e);
            return booklist;

My Book Adapter:

    public class BookAdapter extends ArrayAdapter<Book> {
    public BookAdapter(Context c, ArrayList<Book> book) {
        super(c, 0, book);

    public View getView(int position, @Nullable View convertView, @NonNull ViewGroup parent) {

        View list = convertView;
        if (list == null) {
            list = LayoutInflater.from(getContext()).inflate(R.layout.item, parent, false);

        Book b = getItem(position);

        TextView titleTextView = (TextView) list.findViewById(R.id.title);

        TextView author = (TextView) list.findViewById(R.id.author);

        return list;

It looks like you missed calling your asynctask inside activity

protected void onCreate(Bundle savedInstanceState) {

 list = (ListView) findViewById(R.id.list);
new BookAsynck().execute(bookUrl);

Android Cookbook: Problems and Solutions for Android Developers, As explained in the Processes and Threads” section of the Android the UI thread (a.k.a. the main thread) in several ways, but using the AsyncTask class is very user a spinner in the title bar and updating the ListView once the processing is done. This is the typical use case, not interfering with the user's task at hand and  Many times we need to populate Android Listview using AsyncTask. This is the case when we have to invoke a remote server and exchange information using JSON. In this post, I want to go a bit deeper into the ListView analysis. In the previous posts, I described how to use ListView in several ways using standard and custom adapters. In all the

Welcome to stackoverflow !!

Beginning at Android 9, requests without encryption will not work, that means HttpsURLConnection will work but HttpURLConnection will not.

Then the URL you try to connect must have a https:// access or you should include this in your manifest


Lennken Test, 200. Making. ListView. Scrolling. Smooth. Content from In the sample code below, an AsyncTask is used to load images in a background thread It also shows a progress spinner in place of the images while they are loading. // Using an  AsyncTask class allows you to perform background operations and passing the results on the UI thread. We can use it for performing network operations. Android JSON ListView AsyncTask Example.

Change the below line from onCreate()

ListView list = (ListView) findViewById(R.id.list);


list = (ListView) findViewById(R.id.list);

Xamarin Mobile Application Development for Android, with. async. and. await. Downloading data from the server is a long-running blocking operation, and it is recommended can be used when no result is expected. is the result expected on POIListActivity for rendering the data on the list view. If you do not use this ID or do not include a ListView into your layout, the application crashes once you try to display the activity or the fragment. 5.3. Placeholder for an empty list

Building Xamarin.Forms Mobile Apps Using XAML: Mobile , Both can happen when a user taps a cell in the ListView. In simple lists where there is no unselection of rows (like the example here), there is little difference between them. must be implemented in the C# code behind: async void ListViewItemTapped (object Item; await DisplayAlert("Tapped", item + " was selected. When using an adapter and a ListView, we need to make sure to understand how view recycling works. When your ListView is connected to an adapter, the adapter will instantiate rows until the ListView has been fully populated with enough items to fill the full height of the screen. At that point, no additional row items are created in memory.

The AsyncTask class, LayoutParams · ListPopupWindow · ListView · ListView. AsyncTask was intended to enable proper and easy use of the UI thread. exceptions from doInBackground , and does not provide much utility over using Executor s directly​. This method is used to display any form of progress in the user interface while the  This is the first time that I have played around with AsyncTask in Android and I wanted to make sure I'm using it correctly. The idea is I'm grabbing all the rows from a table in the database using dao and putting them into an Arraylist based off my Item class. Once finished, I added it to a custom Adapter and add it to my ListView.

ListView, A list view is an adapter view that does not know the details, such as type and a list view with a CursorAdapter, see the discussion of filling an adapter view  A few common use cases for ListView include lists of messages and search results. Collections that need to be displayed in multiple columns or in a table-like format should not use ListView, but should look into using a DataGrid instead. GridView. The GridView presents a collection of items in rows and columns that can scroll vertically.