Nullpointerexception: attempt to invoke interface method
<p>I have a list view which when swiped on list item gives menu containing buttons (I have used <a href="https://github.com/baoyongzhang/SwipeMenuListView" rel="nofollow">swipe menu ListView</a> library for this to work). Now when the list item is swiped and a button is clicked in it I want the list item to get added into archives and get displayed in another activity (for this I am using sharedpreference). Adding to sharedpreference and displaying into other activity works fine. But when in the archives activity where the archives list is displayed, I want to remove the list item when pressed on the button in swiped menu. Here the app crashes </p>

<p><strong>My activity where added archives are displayed</strong></p>

<pre><code> public class ProActivity extends Activity
  {

 SwipeMenuListView archiveseList;
     ArchivePreferences archvprefernces;
     List&lt;CodeList&gt; archives;
     SharedPreference shrdprefernces;
     FinalAdapter fnladpter;
     List &lt;CodeList&gt; codelist = null;

@Override
protected void onCreate(Bundle savedInstanceState)
{

    super.onCreate(savedInstanceState);
    setContentView(R.layout.pro_layout);

    archvprefernces = new ArchivePreferences();
    shrdprefernces = new SharedPreference();

    archives = archvprefernces.getArchives(ProActivity.this);
codelist = new ArrayList&lt;CodeList&gt;();

    if (archives == null) {
        showAlert(getResources().getString(R.string.nofav),
                  getResources().getString(R.string.nofavmsg));
    } else {

        if (archives.size() == 0) {
            showAlert(
                getResources().getString(R.string.nofav),
                getResources().getString(R.string.nofavmsg));
        }

        archiveseList = (SwipeMenuListView) findViewById(R.id.pro_layoutListView);
        if (archives != null) {

            fnladpter = new FinalAdapter(ProActivity.this, archives);
            archiveseList.setAdapter(fnladpter);


            SwipeMenuCreator creator = new SwipeMenuCreator() {

                @Override
                public void create(SwipeMenu menu) {
                    // create "open" item
                    SwipeMenuItem openItem = new SwipeMenuItem(ProActivity.this);
                    // set item background
                    openItem.setBackground(new ColorDrawable(Color.rgb(0xC9, 0xC9,
                                                                       0xCE)));
                    // set item width
                    openItem.setWidth(dp2px(90));
                    // set item title
                    openItem.setTitle("Open");
                    // set item title fontsize
                    openItem.setTitleSize(18);
                    // set item title font color
                    openItem.setTitleColor(Color.WHITE);
                    // add to menu
                    menu.addMenuItem(openItem);

                    // create "delete" item
                    SwipeMenuItem favoriteItem = new SwipeMenuItem(ProActivity.this);
                    // set item background
                    favoriteItem.setBackground(new ColorDrawable(Color.rgb(0xF9,
                                                                           0x3F, 0x25)));
                    // set item width
                    favoriteItem.setWidth(dp2px(90));
                    // set a icon
                    favoriteItem.setIcon(R.drawable.unfavorite);

                    // add to menu
                    menu.addMenuItem(favoriteItem);

                    SwipeMenuItem info = new SwipeMenuItem(ProActivity.this);

                    info.setBackground(new ColorDrawable(Color.BLUE));
                    info.setTitle(R.id.beg_list_itemTextView);
                    //set item width
                    info.setWidth(dp2px(90));
                    // set a icon
                    info.setIcon(R.drawable.ic_launcher);
                    // add to menu
                    menu.addMenuItem(info);

                }
            };
            // set creator
            archiveseList.setMenuCreator(creator);

            archiveseList.setOnMenuItemClickListener(new SwipeMenuListView.OnMenuItemClickListener() {
                    @Override
                    public boolean onMenuItemClick(int position, SwipeMenu menu, int index) {
                        //ApplicationInfo item = mAppList.get(position);
                        switch (index) {
                            case 0:
                                // open

                                break;
                            case 1:
                                // favorite


                                break;

                            case 2 :



                                ImageView alphimg = (ImageView) findViewById(R.id.beg_list_itemImageView);
                                String tag = alphimg.getTag().toString();
                                if (checkArchivedItem(codelist.get(position))) {

                                    archvprefernces.removeArchive(ProActivity.this, codelist.get(position));
                                    alphimg.setTag("noarchive");
                                    codelist.add(codelist.get(position));
                                    fnladpter.remove(archives.get(position));
                                    fnladpter.notifyDataSetChanged();
                        Toast.makeText(ProActivity.this, getString(R.string.archive_removed), Toast.LENGTH_SHORT).show();           

                                }else {



                                    archvprefernces.addArchive(ProActivity.this, codelist.get(position));
                                    alphimg.setTag("yesarchive");
                                    codelist.remove(codelist.get(position));

                                    fnladpter.notifyDataSetChanged();

                            }



                                break;


                        }
                        return false;
                    }

                    private boolean checkArchivedItem(CodeList checkcode) {
                        boolean check = false;
                        List&lt;CodeList&gt; archives = archvprefernces.getArchives(ProActivity.this);
                        if (archives != null) {
                            for (CodeList codes : archives) {
                                if (codes.equals(checkcode)) {
                                    check = true;
                                    break;
                                }
                            }
                        }
                        return check;
                    }       

                    private Object getItem(int position)
                    {
                        return codelist.get(position);
                    }





                });

            archiveseList.setOnSwipeListener(new SwipeMenuListView.OnSwipeListener() {

                    @Override
                    public void onSwipeStart(int position) {
                        // swipe start

                    }

                    @Override
                    public void onSwipeEnd(int position) {
                        // swipe end
                    }
                });

            // set MenuStateChangeListener
            archiveseList.setOnMenuStateChangeListener(new SwipeMenuListView.OnMenuStateChangeListener() {
                    @Override
                    public void onMenuOpen(int position) {
                    }

                    @Override
                    public void onMenuClose(int position) {
                    }
                });

            archiveseList.setSwipeDirection(SwipeMenuListView.DIRECTION_LEFT);


            archiveseList.setOnItemClickListener(new OnItemClickListener() {

                    public void onItemClick(AdapterView&lt;?&gt; parent, View arg1,
                                            int position, long arg3) {




                    }
                });



public void showAlert(String title, String message) {
    if (ProActivity.this != null &amp;&amp; !ProActivity.this.isFinishing()) {
        AlertDialog alertDialog = new AlertDialog.Builder(ProActivity.this)
            .create();
        alertDialog.setTitle(title);
        alertDialog.setMessage(message);
        alertDialog.setCancelable(false);

        // setting OK Button
        alertDialog.setButton(AlertDialog.BUTTON_POSITIVE, "OK",
            new DialogInterface.OnClickListener() {

                public void onClick(DialogInterface dialog, int which) {
                    dialog.dismiss();
                    // activity.finish();
                    getFragmentManager().popBackStackImmediate();
                }
            });
        alertDialog.show();
    }


}

private int dp2px(int dp) {
    return (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, dp,
                                           getResources().getDisplayMetrics());
}

@Override
public void onBackPressed() {
    super.onBackPressed();

    overridePendingTransition(R.anim.left_to_right, R.anim.right_to_left);

}
</code></pre>

<p>}</p>

<p><strong>my logcat</strong></p>

<pre><code>01-17 16:38:26.033 12088 12088 D   AndroidRuntime                               Shutting down VM
01-17 16:38:26.051 12088 12088 E   AndroidRuntime                               FATAL EXCEPTION: main
01-17 16:38:26.051 12088 12088 E   AndroidRuntime                               Process: com.enlightenme.pac, PID: 12088
01-17 16:38:26.051 12088 12088 E   AndroidRuntime                               java.lang.IndexOutOfBoundsException: Invalid index 2, size is 0
01-17 16:38:26.051 12088 12088 E   AndroidRuntime                               at java.util.ArrayList.throwIndexOutOfBoundsException(ArrayList.java:255)
01-17 16:38:26.051 12088 12088 E   AndroidRuntime                               at java.util.ArrayList.get(ArrayList.java:308)
01-17 16:38:26.051 12088 12088 E   AndroidRuntime                               at com.enlightenme.pac.ProActivity$100000001.onMenuItemClick(ProActivity.java:209)
01-17 16:38:26.051 12088 12088 E   AndroidRuntime                               at com.baoyz.swipemenulistview.SwipeMenuListView$100000000.onItemClick(SwipeMenuListView.java:78)
01-17 16:38:26.051 12088 12088 E   AndroidRuntime                               at com.baoyz.swipemenulistview.SwipeMenuView.onClick(SwipeMenuView.java:85)
01-17 16:38:26.051 12088 12088 E   AndroidRuntime                               at android.view.View.performClick(View.java:4780)
01-17 16:38:26.051 12088 12088 E   AndroidRuntime                               at android.view.View$PerformClick.run(View.java:19866)
01-17 16:38:26.051 12088 12088 E   AndroidRuntime                               at android.os.Handler.handleCallback(Handler.java:739)
01-17 16:38:26.051 12088 12088 E   AndroidRuntime                               at android.os.Handler.dispatchMessage(Handler.java:95)
01-17 16:38:26.051 12088 12088 E   AndroidRuntime                               at android.os.Looper.loop(Looper.java:135)
01-17 16:38:26.051 12088 12088 E   AndroidRuntime                               at android.app.ActivityThread.main(ActivityThread.java:5254)
01-17 16:38:26.051 12088 12088 E   AndroidRuntime                               at java.lang.reflect.Method.invoke(Native Method)
01-17 16:38:26.051 12088 12088 E   AndroidRuntime                               at java.lang.reflect.Method.invoke(Method.java:372)
01-17 16:38:26.051 12088 12088 E   AndroidRuntime                               at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:903)
</code></pre>