{"action":"created","issue":{"url":"https://api.github.com/repos/neokree/MaterialNavigationDrawer/issues/214","labels_url":"https://api.github.com/repos/neokree/MaterialNavigationDrawer/issues/214/labels{/name}","comments_url":"https://api.github.com/repos/neokree/MaterialNavigationDrawer/issues/214/comments","events_url":"https://api.github.com/repos/neokree/MaterialNavigationDrawer/issues/214/events","html_url":"https://github.com/neokree/MaterialNavigationDrawer/issues/214","id":59895333,"number":214,"title":"java.lang.IndexOutOfBoundsException when selecting section from child","user":{"login":"vangliana","id":5017163,"avatar_url":"https://avatars.githubusercontent.com/u/5017163?v=3","gravatar_id":"","url":"https://api.github.com/users/vangliana","html_url":"https://github.com/vangliana","followers_url":"https://api.github.com/users/vangliana/followers","following_url":"https://api.github.com/users/vangliana/following{/other_user}","gists_url":"https://api.github.com/users/vangliana/gists{/gist_id}","starred_url":"https://api.github.com/users/vangliana/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/vangliana/subscriptions","organizations_url":"https://api.github.com/users/vangliana/orgs","repos_url":"https://api.github.com/users/vangliana/repos","events_url":"https://api.github.com/users/vangliana/events{/privacy}","received_events_url":"https://api.github.com/users/vangliana/received_events","type":"User","site_admin":false},"labels":[{"url":"https://api.github.com/repos/neokree/MaterialNavigationDrawer/labels/bug","name":"bug","color":"fc2929"},{"url":"https://api.github.com/repos/neokree/MaterialNavigationDrawer/labels/testing","name":"testing","color":"eb6420"}],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":9,"created_at":"2015-03-05T02:24:37Z","updated_at":"2015-03-23T23:34:00Z","closed_at":null,"body":"Hi Folks,\r\n\r\nI get the following exception when changing to another section from a child section:\r\n```\r\njava.lang.IndexOutOfBoundsException\r\n            at java.util.LinkedList.remove(LinkedList.java:660)\r\n            at it.neokree.materialnavigationdrawer.MaterialNavigationDrawer.setFragment(MaterialNavigationDrawer.java:968)\r\n```\r\n\r\nMy code to change to a section is as following:\r\n```\r\npublic void selectSection(final Class<? extends BaseFragment> targetFragmentClazz) {\r\n        final MaterialSection currentSection = getCurrentSection();\r\n        final MaterialSection targetSection = getSection(targetFragmentClazz);\r\n        currentSection.unSelect();\r\n        setFragment(targetSection.getTargetFragment(), targetSection.getTitle());\r\n        setSection(targetSection);\r\n        targetSection.select();\r\n    }\r\n```\r\n\r\nEdit:\r\n\r\nAfter doing some investigation, it seems to me that the problem is here in this line ' else for(int i = childFragmentStack.size()-1;i >= 0;i++)'  in the following method:\r\n```\r\n/**\r\n     * Set the fragment to the activity content.<br />\r\n     * N.B. If you want to support the master/child flow, please consider to use setFragmentChild instead\r\n     *\r\n     * @param fragment to replace into the main content\r\n     * @param title to set into Toolbar\r\n     */\r\n    public void setFragment(Fragment fragment,String title) {\r\n        setFragment(fragment,title,null);\r\n\r\n        if(!isCurrentFragmentChild) {// remove the last child from the stack\r\n            childFragmentStack.remove(childFragmentStack.size() - 1);\r\n            childTitleStack.remove(childTitleStack.size() - 1);\r\n        }\r\n        else for(int i = childFragmentStack.size()-1;i >= 0;i++) { // if a section is clicked when user is into a child remove all childs from stack\r\n            childFragmentStack.remove(i);\r\n            childTitleStack.remove(i);\r\n        }\r\n\r\n        // add to the childStack the Fragment and title\r\n        childFragmentStack.add(fragment);\r\n        childTitleStack.add(title);\r\n\r\n        isCurrentFragmentChild = false;\r\n    }\r\n```\r\n\r\nPerhaps the loop need to be:\r\n```\r\n for(int i = childFragmentStack.size()-1;i >= 0;i--)\r\n```"},"comment":{"url":"https://api.github.com/repos/neokree/MaterialNavigationDrawer/issues/comments/85246603","html_url":"https://github.com/neokree/MaterialNavigationDrawer/issues/214#issuecomment-85246603","issue_url":"https://api.github.com/repos/neokree/MaterialNavigationDrawer/issues/214","id":85246603,"user":{"login":"vangliana","id":5017163,"avatar_url":"https://avatars.githubusercontent.com/u/5017163?v=3","gravatar_id":"","url":"https://api.github.com/users/vangliana","html_url":"https://github.com/vangliana","followers_url":"https://api.github.com/users/vangliana/followers","following_url":"https://api.github.com/users/vangliana/following{/other_user}","gists_url":"https://api.github.com/users/vangliana/gists{/gist_id}","starred_url":"https://api.github.com/users/vangliana/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/vangliana/subscriptions","organizations_url":"https://api.github.com/users/vangliana/orgs","repos_url":"https://api.github.com/users/vangliana/repos","events_url":"https://api.github.com/users/vangliana/events{/privacy}","received_events_url":"https://api.github.com/users/vangliana/received_events","type":"User","site_admin":false},"created_at":"2015-03-23T23:34:00Z","updated_at":"2015-03-23T23:34:00Z","body":"@neokree I just tried release 1.3.3 and setSection still doesn't work. I can see the code was changed for this method, but can you please confirm whether it was fixed?\r\n\r\nAlso, I have some logic that sits in MaterialNavigationDrawer#onClick method that keeps track of which section has been selected and updates the toolbar and drawer header accordingly. Will onClick still be called when setting the section programatically? if not, where would be the best place to check which section has been selected?\r\n\r\nCheers"}}