Dependent spinner crashes when Parent spinner change multiple times (json value)

I have two Spinners the GetClient(spinnerCompany) and GetBusinessUnit(spinnerBusinessUnit), the values of the spinners value is json and I have to map the values to get the (Key, Value) so that I can pass the ID to GetBusinessUnit whenever the value of Parent Spinner(GetClient) changes. My problem is that whenever I change the GetClient multiple times it throws an error

java.lang.IndexOutOfBoundsException: Invalid index 2, size is 1

private class getClient extends AsyncTask<Object, Object, String> {
    HttpURLConnection conn;
    URL url = null;
    int response_code;

    @Override
    protected String doInBackground(Object... voids) {
        try {
            url = new URL("http://"+ip_add+"/client_product/client_product");

        } catch (MalformedURLException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
            return e.toString();
        }
        try {
            // Setup HttpURLConnection class to send and receive data from php and mysql
            conn = (HttpURLConnection) url.openConnection();
            conn.setReadTimeout(READ_TIMEOUT);
            conn.setConnectTimeout(CONNECTION_TIMEOUT);
            conn.setRequestMethod("GET");

        } catch (IOException e1) {
            // TODO Auto-generated catch block
            e1.printStackTrace();
            return e1.toString();
        }
        try {
            response_code = conn.getResponseCode();

            // Check if successful connection made
            if (response_code == HttpURLConnection.HTTP_OK) {

                // Read data sent from server
                InputStream input = conn.getInputStream();
                BufferedReader reader = new BufferedReader(new InputStreamReader(input));
                StringBuilder result = new StringBuilder();
                String line;

                while ((line = reader.readLine()) != null) {
                    result.append(line);
                }
                // Pass data to onPostExecute method
                return (result.toString());

            } else {
                return ("unsuccessful");
            }
        } catch (IOException e) {
            e.printStackTrace();
            return e.toString();
        } finally {
            conn.disconnect();
        }
    }


    @Override
    protected void onPostExecute(String result) {
        try {
            Log.e("Try", "Start");
            if (conn.getResponseCode() == 200) {
                Log.e("Try", "Connection Established Waiting for API response");
                data = new ArrayList<HashMap<String, String>>();
                try {

                    JSONObject object = new JSONObject(result);
                    JSONObject data_res = object.getJSONObject("data");
                    JSONArray data_array = data_res.getJSONArray("product");

                    for(int i=0; i < data_array.length() ; i++) {
                        JSONObject c = data_array.getJSONObject(i);
                        HashMap<String, String> map = new HashMap<>();

                        map.put("id", c.getString("id"));
                        map.put("product_name", c.getString("product_name"));

                        data.add(map);

                    }

                    String[] arrClient=new String[data.size()];
                    for(int index =0; index < data.size();index++){
                        HashMap<String, String> map = data.get(index);
                        arrClient[index]=map.get("product_name");
                    }

                    ArrayAdapter<String> spinnerArrayAdapter = new ArrayAdapter<String>(ShipmentDetailsActivity.this,android.R.layout.simple_spinner_dropdown_item, arrClient);
                    spinnerCompany.setAdapter(spinnerArrayAdapter);
spinnerCompany.setOnItemSelectedListener(new 
AdapterView.OnItemSelectedListener() {
        @Override
        public void onItemSelected(AdapterView<?> adapterView, View view, int i, long l) {

            if(spinnerCompany.getSelectedItemId() == 0) {
            } else if (spinnerCompany.getSelectedItemId() != 0) {
                String selected_str = data.get(i).get("id");
                new getBusinessUnit(selected_str).execute();
            }
        }

        @Override
        public void onNothingSelected(AdapterView<?> adapterView) {

        }
    });

                } catch (JSONException e) {
                }

            } else {
            }
        } catch (Exception e){
        }
    }
}

This is the BusinessUnit Spinner.

private class getBusinessUnit extends AsyncTask<String, String, String> {
    HttpURLConnection conn;
    URL url = null;
    int response_code;
    String selected_str;

    public getBusinessUnit(String selected_str) {
        this.selected_str = selected_str;
    }
    @Override
    protected String doInBackground(String... params) {
        try {
            // Enter URL address where your php file resides
            url = new URL("http://"+ip_add+"/client_product/business_unit?client_product_id="+selected_str+"");
        } catch (MalformedURLException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
            return e.toString();
        }
        try {
            // Setup HttpURLConnection class to send and receive data from php and mysql
            conn = (HttpURLConnection) url.openConnection();
            conn.setReadTimeout(READ_TIMEOUT);
            conn.setConnectTimeout(CONNECTION_TIMEOUT);
            conn.setRequestMethod("GET");

        } catch (IOException e1) {
            // TODO Auto-generated catch block
            e1.printStackTrace();
            return e1.toString();
        }
        try {
            response_code = conn.getResponseCode();

            // Check if successful connection made
            if (response_code == HttpURLConnection.HTTP_OK) {

                // Read data sent from server
                InputStream input = conn.getInputStream();
                BufferedReader reader = new BufferedReader(new InputStreamReader(input));
                StringBuilder result = new StringBuilder();
                String line;

                while ((line = reader.readLine()) != null) {
                    result.append(line);
                }
                // Pass data to onPostExecute method
                return (result.toString());

            } else {
                return ("unsuccessful");
            }
        } catch (IOException e) {
            e.printStackTrace();
            return e.toString();
        } finally {
            conn.disconnect();
        }
    }

    @Override
    protected void onPostExecute(String result) {
        try {
            Log.e("Try", "Start");
            if (conn.getResponseCode() == 200) {
                Log.e("Try", "Connection Established Waiting for API response");
                data = new ArrayList<HashMap<String, String>>();
                try {

                    JSONObject object = new JSONObject(result);
                    JSONObject data_res = object.getJSONObject("data");
                    JSONArray data_array = data_res.getJSONArray("business_unit");

                    for(int i=0; i < data_array.length() ; i++) {
                        JSONObject c = data_array.getJSONObject(i);
                        HashMap<String, String> map = new HashMap<>();

                        map.put("id", c.getString("id"));
                        map.put("bunit_desc", c.getString("bunit_desc"));

                        data.add(map);

                    }

                    String[] arrBusiness=new String[data.size()];
                    for(int index =0; index < data.size();index++){
                        HashMap<String, String> map = data.get(index);
                        arrBusiness[index]=map.get("bunit_desc");
                    }

                    ArrayAdapter<String> spinnerArrayAdapter = new 
ArrayAdapter<String>(ShipmentDetailsActivity.this,android.R.layout.simple_spinner_dropdown_item, arrBusiness);

spinnerBusinessUnit.setAdapter(spinnerArrayAdapter);
 spinnerBusinessUnit.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
        @Override
        public void onItemSelected(AdapterView<?> adapterView, View view, int i, long l) {
            if (spinnerBusinessUnit.getSelectedItemId() == 0) {
            } else if (spinnerBusinessUnit.getSelectedItemId() != 0) {
                String selected_id = data.get(i).get("id");
                //business.setText(selected_id);
            }
        }

        @Override
        public void onNothingSelected(AdapterView<?> adapterView) {

        }
    });

                } catch (JSONException e) {
                }

            } else {
            }
        } catch (Exception e){
        }
    }
}