ncapdevi / FragNav

An Android library for managing multiple stacks of fragments
1.5k stars 220 forks source link

Crash on pushFragment #218

Closed dajver closed 5 years ago

dajver commented 5 years ago

Hey, Im trying to use your library, but I can't understand why its crashing all the time when I try to pushFragment:

mFragNavController.pushFragment(StoryEditFragment.newInstance(story));

java.lang.IndexOutOfBoundsException: Index: 0, Size: 0 at java.util.ArrayList.get(ArrayList.java:437) at com.ncapdevi.fragnav.FragNavController.pushFragment(FragNavController.kt:299) at com.ncapdevi.fragnav.FragNavController.pushFragment$default(FragNavController.kt:292) at com.ncapdevi.fragnav.FragNavController.pushFragment(Unknown Source:2) at com.hi_storyapp.screens.common.screensnavigator.ScreensNavigator.toTemplates(ScreensNavigator.java:76) at com.hi_storyapp.screens.collections.CollectionsController.onCollectionClicked(CollectionsController.java:102) at com.hi_storyapp.screens.collections.CollectionsViewMvcImpl.onCollectionClicked(CollectionsViewMvcImpl.java:116) at com.hi_storyapp.screens.collections.CollectionsAdapter.onCollectionClicked(CollectionsAdapter.java:76) at com.hi_storyapp.screens.collections.listitem.CollectionsListItemViewMvcImpl.lambda$new$0(CollectionsListItemViewMvcImpl.java:56) at com.hi_storyapp.screens.collections.listitem.-$$Lambda$CollectionsListItemViewMvcImpl$1SxPzGZxqtOm_GlsBsjIJM0zPsI.onClick(Unknown Source:2) at android.view.View.performClick(View.java:6256) at android.view.View$PerformClick.run(View.java:24701) at android.os.Handler.handleCallback(Handler.java:789) at android.os.Handler.dispatchMessage(Handler.java:98) at android.os.Looper.loop(Looper.java:164) at android.app.ActivityThread.main(ActivityThread.java:6541) at java.lang.reflect.Method.invoke(Native Method) at com.android.internal.os.Zygote$MethodAndArgsCaller.run(Zygote.java:240) at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:767)

It's says that stack is empty, but I don't understand how to add to this stack fragments which I want to push... And it link to fragmentStacksTags[currentStackIndex].push(fragmentTag). As I understood currentStackIndex = 0. Or maybe fragmentStacksTags is empty.

replaceFragment has same problem it even doesn't work, no crash no anything , but switch tab works well...

When I use standart replace fragment everything works fine...

dajver commented 5 years ago

Found problem, it's very important to use fragment or activity with context. But I wanted use it in different class which didn't have actual context...

ncapdevi commented 5 years ago

👍 @dajver Thanks for taking the time to come back with your solution and closing the issue.