lundi 27 février 2017

When trying to acces an Arraylist from the doInbackground gives a null arraylist

I have an arraylist of 2800 item which i have obtained from a json file when I try to devide the arraylist using this method

the mainActivity goes like this

 ArrayList<view > arr = new ArrayList<view>();
ArrayList<view> arran = arr;
            arran = utils.arrydivider(arr);
        final ListView poem_Title_list = (ListView) findViewById(R.id.list_item);
        madapter = new title_adapter(this ,arran);
        poem_Title_list.setAdapter(madapter);

and the deviearray method goes like this

public static ArrayList<view> arrydivider (ArrayList<view> completearray ){
        ArrayList<view> deivedArray = new ArrayList<view>();
        Random rand = new Random();

        int  n = rand.nextInt(2000);

        for(int i =0 ; i<10;i++){
            deivedArray.add(completearray.get(n+i));
        }
        return deivedArray;
  }

the Asynctask class is just working fine but here it is

 private class TitleAsynctask extends AsyncTask<URL,Void,List<view>> {

     private ProgressDialog progressDialog;
            @Override
            public List<view> doInBackground(URL... urls){

                URL url = Query_utils.createurl(POEM_TITLE);
                String json = "";
                Log.d(LOG_TAG,"this worked");
                {
                    try {
                        json = Query_utils.makehttprequest(url);
                        Log.d(LOG_TAG, "make Httprequest works");
                    } catch (IOException e) {
      }
                }
                List<view> title_view = Query_utils.extracttitlefromjson(json);
                return title_view;

            }
          @RequiresApi(api = Build.VERSION_CODES.HONEYCOMB)
            @Override
            protected void onPostExecute(List<view> data) {
                madapter.clear();

       if (data != null && !data.isEmpty()){
                    madapter.addAll(data);
                }
            }
     }




Aucun commentaire:

Enregistrer un commentaire