Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

java.lang.RuntimeException: Could not dispatch event #8

Open
strmchsr opened this issue Jan 12, 2016 · 14 comments
Open

java.lang.RuntimeException: Could not dispatch event #8

strmchsr opened this issue Jan 12, 2016 · 14 comments

Comments

@strmchsr
Copy link

I am facing the following issue sometimes:

Fatal Exception: java.lang.RuntimeException: Could not dispatch event: class noman.weekcalendar.eventbus.Event$SetSelectedDateEvent to handler [EventHandler public void noman.weekcalendar.view.WeekPager.setSelectedDate(noman.weekcalendar.eventbus.Event$SetSelectedDateEvent)]: Fragment WeekFragment{426ab190} is not currently in the FragmentManager
at com.squareup.otto.Bus.throwRuntimeException(Bus.java:460)
at com.squareup.otto.Bus.dispatch(Bus.java:387)
at com.squareup.otto.Bus.dispatchQueuedEvents(Bus.java:368)
at com.squareup.otto.Bus.post(Bus.java:337)
at noman.weekcalendar.eventbus.BusProvider.post(BusProvider.java:26)
at noman.weekcalendar.WeekCalendar.setSelectedDate(WeekCalendar.java:165)
at com.kwench.android.kfit.ui.SleepFragment$1$1.onDateSet(SleepFragment.java:147)
at android.app.DatePickerDialog.tryNotifyDateSet(DatePickerDialog.java:148)
at android.app.DatePickerDialog.onClick(DatePickerDialog.java:116)
at com.android.internal.app.AlertController$ButtonHandler.handleMessage(AlertController.java:166)
at android.os.Handler.dispatchMessage(Handler.java:110)
at android.os.Looper.loop(Looper.java:193)
at android.app.ActivityThread.main(ActivityThread.java:5345)
at java.lang.reflect.Method.invokeNative(Method.java)
at java.lang.reflect.Method.invoke(Method.java:515)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:828)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:644)
at dalvik.system.NativeStart.main(NativeStart.java)
Caused by java.lang.IllegalStateException: Fragment WeekFragment{426ab190} is not currently in the FragmentManager
at android.support.v4.app.FragmentManagerImpl.saveFragmentInstanceState(FragmentManager.java:687)
at android.support.v4.app.FragmentStatePagerAdapter.destroyItem(FragmentStatePagerAdapter.java:136)
at android.support.v4.view.ViewPager.setAdapter(ViewPager.java:418)
at noman.weekcalendar.view.WeekPager.initPager(WeekPager.java:56)
at noman.weekcalendar.view.WeekPager.setSelectedDate(WeekPager.java:102)
at java.lang.reflect.Method.invokeNative(Method.java)
at java.lang.reflect.Method.invoke(Method.java:515)
at com.squareup.otto.EventHandler.handleEvent(EventHandler.java:89)
at com.squareup.otto.Bus.dispatch(Bus.java:385)
at com.squareup.otto.Bus.dispatchQueuedEvents(Bus.java:368)
at com.squareup.otto.Bus.post(Bus.java:337)
at noman.weekcalendar.eventbus.BusProvider.post(BusProvider.java:26)
at noman.weekcalendar.WeekCalendar.setSelectedDate(WeekCalendar.java:165)
at com.kwench.android.kfit.ui.SleepFragment$1$1.onDateSet(SleepFragment.java:147)
at android.app.DatePickerDialog.tryNotifyDateSet(DatePickerDialog.java:148)
at android.app.DatePickerDialog.onClick(DatePickerDialog.java:116)
at com.android.internal.app.AlertController$ButtonHandler.handleMessage(AlertController.java:166)
at android.os.Handler.dispatchMessage(Handler.java:110)
at android.os.Looper.loop(Looper.java:193)
at android.app.ActivityThread.main(ActivityThread.java:5345)
at java.lang.reflect.Method.invokeNative(Method.java)
at java.lang.reflect.Method.invoke(Method.java:515)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:828)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:644)
at dalvik.system.NativeStart.main(NativeStart.java)

@nomanr
Copy link
Owner

nomanr commented Jan 12, 2016

Are you using the calendar view inside a fragment?

@Ramfat
Copy link

Ramfat commented Jan 12, 2016

I am using my calendar view inside an AppCompatActivity and have the same problem. So using getChildFragmentManager will not work in this instance (if that is what you were gonna suggest).

@strmchsr
Copy link
Author

yes,
What is the resolution?

@michel-t-86
Copy link
Contributor

This is a memory leak issue.

When the activity is destroyed, somehow the WeekPager of the WeekCalendar view remains in memory.

When a new activity is created and a call is made to a fresh WeekCalendar, the BusProvider dispatches the event to both the leaked WeekPager and the new WeekPager.
The event will work fine for the new WeekPager but will fail for the old one.

I don't know enough about Views' lifecycle to fix it but I've done a temporary hack in WeekPager by surrounding the code of every method marked as @subscribe with a try/catch.

@michel-t-86
Copy link
Contributor

Found it.

BusProvider is a singleton that is never disposed of and hence maintains a reference to methods within the old WeekPager.

I'll fix it and do a pull request when I get around to it.

@nomanr
Copy link
Owner

nomanr commented Feb 1, 2016

You are welcome to contribute to this library and fix the issue you found.
On Feb 1, 2016 9:50 PM, "BroScience repository" notifications@github.com
wrote:

Found it.

BusProvider is a singleton that is never disposed of and hence maintains a
reference to methods within the old WeekPager.

Implement the proper design pattern and it fixes it.


Reply to this email directly or view it on GitHub
#8 (comment).

@michel-t-86
Copy link
Contributor

Pull request created

@strmchsr
Copy link
Author

strmchsr commented Feb 2, 2016

is it fixed?

@nomanr
Copy link
Owner

nomanr commented Feb 2, 2016

Yes, you need to download and add the library. Haven't updated in on Maven
yet.
On Feb 2, 2016 4:08 PM, "shashank090789" notifications@github.com wrote:

is it fixed?


Reply to this email directly or view it on GitHub
#8 (comment).

@cenkgun
Copy link

cenkgun commented Feb 15, 2017

I got the same problem. What's the solution?

@konstantin-gorbunov
Copy link

me too :(

@cenkgun
Copy link

cenkgun commented Jun 22, 2017

@konstantin-gorbunov I couldn't solve this problem. Suggest this library, https://github.com/Mulham-Raee/Horizontal-Calendar.

@mihir-trivedi-indianic
Copy link

Getting the Same Problem is there any solution or anyone get the solution?

@mihir-trivedi-indianic
Copy link

mihir-trivedi-indianic commented Sep 5, 2018

I will get the solution for only to prevent a crash. Change BusProvider lib

from com.squareup:otto to org.greenrobot:eventbus

But it will not override the WeekCalendar view in newly added fragment also not showing the days. And previous fragment's WeekCalander makes disabled.

firstfragmentview
secondfragementview
firstfragementviewaftercomebackfromsecondfragment

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

7 participants