java.lang.ArrayIndexOutOfBoundsException: length=5; index=5

i am new in android development. i am working on an app where i am using navigation drawer, in which i have seven items.i am using an arraylist for them to show them on onCreate.

navDrawerItems = new ArrayList<NavDrawerItem>();

    // adding nav drawer items to array
    // Home
    navDrawerItems.add(new NavDrawerItem(navMenuTitles[0], navMenuIcons.getResourceId(0, -1)));
    // Find People
    navDrawerItems.add(new NavDrawerItem(navMenuTitles[1], navMenuIcons.getResourceId(1, -1)));
    // Photos
    navDrawerItems.add(new NavDrawerItem(navMenuTitles[2], navMenuIcons.getResourceId(2, -1)));
    // Communities, Will add a counter here
    navDrawerItems.add(new NavDrawerItem(navMenuTitles[3], navMenuIcons.getResourceId(3, -1), true, "22"));
    // Pages
    navDrawerItems.add(new NavDrawerItem(navMenuTitles[4], navMenuIcons.getResourceId(4, -1)));
    // What's hot, We  will add a counter here
    navDrawerItems.add(new NavDrawerItem(navMenuTitles[5], navMenuIcons.getResourceId(5,-1), true, "50+"));

     navDrawerItems.add(new NavDrawerItem(navMenuTitles[6], navMenuIcons.getResourceId(6, -1)));

but i am facing this problem.

Caused by:

java.lang.ArrayIndexOutOfBoundsException: length=5; index=5
            at com.almuntazah.application.Homepage.onCreate(

can anyone please tell me in simple words what should i do?? thank you so much.
actually i get error in last 2 lists. if i remove them, i can’t get in my application.

Source: android

Leave a Reply