2017-03-09 1 views
0

listIterator의 remove 메서드를 사용하려고합니다.idsIterator.remove() throws IllegalStateException

private List<Category> findDescendantsOfCurrentCategory() { 
    List<Category> categoryList = new ArrayList<>(mCategoryList); 

    List<Category> descendantCategories = new ArrayList<>(); 

    Stack<String> categoriesIds = new Stack<>(); 
    categoriesIds.push(mCategoryId); 

    ListIterator<Category> categoryListIterator = categoryList.listIterator(); 

    ListIterator<String> idsIterator = categoriesIds.listIterator(); 

    while (idsIterator.hasNext()) { 
     String parentId = idsIterator.next(); 

     while (categoryListIterator.hasNext()) { 
      Category category = categoryListIterator.next(); 

      if (category.getParentId().equals(parentId)) { 
       idsIterator.add(category.getId()); 

       descendantCategories.add(category); 
      } 

      categoryListIterator.remove(); 
     } 

     idsIterator.remove(); 
    } 

    return descendantCategories; 
} 

스택 추적 :

는 반복자에 대한 설명서 ( https://docs.oracle.com/javase/7/docs/api/java/util/ListIterator.html#remove())을 제거하는 방법에 대해 말한다
03-09 23:11:33.160 25298-25298/com.example.clients.someoneplatform.dev E/AndroidRuntime: FATAL EXCEPTION: main 
       Process: com.example.clients.someoneplatform.dev, PID: 25298 
       java.lang.IllegalStateException 
     at java.util.AbstractList$SimpleListIterator.remove(AbstractList.java:67) 
     at com.example.clients.someoneplatform.ui.categories.list.ListCategoriesFragment.findDescendantsOfCurrentCategory(ListCategoriesFragment.java:186) 
     at com.example.clients.someoneplatform.ui.categories.list.ListCategoriesFragment.startAddEditCategoryForModification(ListCategoriesFragment.java:154) 
     at com.example.clients.someoneplatform.ui.categories.list.ListCategoriesFragment.access$200(ListCategoriesFragment.java:39) 
     at com.example.clients.someoneplatform.ui.categories.list.ListCategoriesFragment$1.onCategoryModifyButtonClicked(ListCategoriesFragment.java:124) 
     at com.example.clients.someoneplatform.ui.categories.list.ListCategoriesAdapter$ViewHolder.onModifyButtonClicked(ListCategoriesAdapter.java:134) 
     at com.example.clients.someoneplatform.ui.categories.list.ListCategoriesAdapter$ViewHolder_ViewBinding$2.doClick(ListCategoriesAdapter$ViewHolder_ViewBinding.java:47) 
     at butterknife.internal.DebouncingOnClickListener.onClick(DebouncingOnClickListener.java:22) 
     at android.view.View.performClick(View.java:5201) 
     at android.view.View$PerformClick.run(View.java:21209) 
     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:5525) 
     at java.lang.reflect.Method.invoke(Native Method) 
     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:730) 
     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:620) 
+0

이 IlligaleStateException 무엇을 말하는가 제거 호출하기 전에 추가 기능을 사용하지 않는 코드를 다시 작성해야? – DZDomi

+0

@DZDomi 아무 것도. – malhobayyeb

+0

스택 추적을 게시하십시오. – Kayaman

답변

1

: "그것은 할 수있다 그러나, 나는 여기 IllegalStateException

을 얻고 나의 코드입니다 add (E)가 next 또는 previous의 마지막 호출 후에 불려 가지 않은 경우에게만 행해진 다.

그래서 당신은 기본적으로 당신이

관련 문제