RecyclerView Array Index out of bound Exception Removing Items
<p>I am making android application that has a <code>RecyclerView</code> and each item contains close button share button and max count and count button when you click the count button times equal to max times it should delete the item . 
after certain amount of time it crashes 
this is the code </p>

<pre><code>    package com.example.ali.azkarv10;

import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.content.SharedPreferences;
import android.graphics.Typeface;
import android.os.Vibrator;
import android.provider.ContactsContract;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Button;
import android.widget.ImageButton;
import android.widget.TextView;
import android.widget.Toast;

import java.util.Collections;
import java.util.List;

/**
 * Created by Ali on 03/06/2016.
 */
public class Recycleradapter extends RecyclerView.Adapter&lt;Recycleradapter.myViewHolder&gt; {
    Context context;
    List&lt;Zekr&gt; list= Collections.emptyList();
    SharedPreferences sharedPreferences;
    SharedPreferences.Editor editor;
    public Recycleradapter(Context context,List&lt;Zekr&gt; list){
        this.context=context;
        this.list=list;
        sharedPreferences=context.getSharedPreferences("data",Context.MODE_PRIVATE);
        editor=sharedPreferences.edit();
    }
    @Override
    public myViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        LayoutInflater inflater=LayoutInflater.from(context);
        View view=inflater.inflate(R.layout.list_azkar_ayout,parent,false);
        myViewHolder holder=new myViewHolder(view);
        return holder;
    }

    @Override
    public void onBindViewHolder(final myViewHolder holder, final int position) {
         Zekr current=list.get(position);
        holder.zekr.setText(current.zekr);
        holder.zekrcount.setText(Integer.toString(current.zekrcount));
        holder.zekrmax.setText(Integer.toString(current.zekrmax));
        holder.zekr.setTypeface(Typeface.createFromAsset(context.getAssets(),sharedPreferences.getString("fontType","fonts/blacksugar.ttf")));
        holder.zekr.setTextSize(sharedPreferences.getInt("fontSize",10));

    }
    public void close(int position){
        list.remove(position);
         notifyItemRemoved(position);
        if(list.isEmpty())
            ((Activity)context)  .finish();     }







    @Override
    public int getItemCount() {
        return list.size();
    }

    class myViewHolder extends RecyclerView.ViewHolder{
        TextView zekr;
        TextView zekrcount;
        TextView zekrmax;
        ImageButton close;
        ImageButton share;
        Button sab;
        public myViewHolder(View itemView) {
            super(itemView);
            zekr=(TextView)itemView.findViewById(R.id.textzekr);
            zekrcount=(TextView)itemView.findViewById(R.id.zekrcount);
            zekrmax=(TextView)itemView.findViewById(R.id.zekrmax);
            close=(ImageButton) itemView.findViewById(R.id.close);
            share=(ImageButton)itemView.findViewById(R.id.share);
            sab=(Button)itemView.findViewById(R.id.zekrButton);
            close.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    close(getAdapterPosition());
                }
            });

            share.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {

                    Intent sendIntent = new Intent();
                    sendIntent.setAction(Intent.ACTION_SEND);
                    sendIntent.putExtra(Intent.EXTRA_TEXT, zekr.getText().toString());
                    sendIntent.setType("text/plain");
                    context.startActivity(Intent.createChooser(sendIntent, context.getResources().getText(R.string.send_to)));
                }
            });

            sab.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    list.get(getAdapterPosition()).zekrcount+=1;
                   zekrcount.setText(Integer.toString( list.get(getAdapterPosition()).zekrcount));
                    if( list.get(getAdapterPosition()).zekrcount== list.get(getAdapterPosition()).zekrmax){
                        close(getAdapterPosition());
                        ////buzzer code
                        if(sharedPreferences.getBoolean("buzzer",true)){
                            Vibrator vibrator=(Vibrator)context.getSystemService(Context.VIBRATOR_SERVICE);
                            vibrator.vibrate(500);

                        }
                    }
                }
            });

}}

}
</code></pre>

<p>My logcat</p>

<pre><code>06-06 12:36:45.335 16747-16747/com.example.ali.azkarv10 E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.example.ali.azkarv10, PID: 16747
java.lang.ArrayIndexOutOfBoundsException: length=40; index=-1
  at java.util.ArrayList.get(ArrayList.java:310)
  at com.example.ali.azkarv10.Recycleradapter$myViewHolder$3.onClick(Recycleradapter.java:108)
  at android.view.View.performClick(View.java:5198)
  at android.view.View$PerformClick.run(View.java:21147)
  at android.os.Handler.handleCallback(Handler.java:739)
  at android.os.Handler.dispatchMessage(Handler.java:95)
  at android.os.Looper.loop(Looper.java:148)
  at android.app.ActivityThread.main(ActivityThread.java:5417)
  at java.lang.reflect.Method.invoke(Native Method)
  at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:726)
  at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616)
</code></pre>