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


i new in android development. working on app using navigation drawer, in have 7 items.i using arraylist them show them on oncreate.

navdraweritems = new arraylist<navdraweritem>();      // adding nav drawer items 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, add 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,  add 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 facing problem.

caused by:

java.lang.arrayindexoutofboundsexception: length=5; index=5             @ com.almuntazah.application.homepage.oncreate(homepage.java:75) 

can please tell me in simple words should do?? thank much. error in last 2 lists. if remove them, can't in application.

you need count 0 last field of array length of 5 4

example:

    string examplearray[]=new string [5];     system.out.println(examplearray.length)     >>>5//this length     examplearray={"1","2","3","4","5"}//filling array     system.out.println(examplearray.length)     >>>5//still same length     system.out.println(examplearray[4])     >>>"5"//the content of examplearray[4] field 

Comments

Popular posts from this blog

toolbar - How to add link to user registration inside toobar in admin joomla 3 custom component -

linux - disk space limitation when creating war file -

How to provide Authorization & Authentication using Asp.net, C#? -