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

RxTextView.textChanges crashes with java.lang.IndexOutOfBoundsException #452

Closed
lennonpetrick opened this issue Jul 27, 2018 · 3 comments
Closed

Comments

@lennonpetrick
Copy link

Hi everyone.

I have a code like:

RxTextView
    .textChanges(editText)
    .take(2)
    .subscribe());

And my EditText has another TextWatcher in order to format its text.

When I type the first character in the EditText, it throws an IndexOutOfBoundsException: Invalid index 2, size is 2.

I figured out that my TextWatcher is making the textChanges' observable emit 2 events.
The first disposes the observable and it unregisters the textChanges listener. And when the second is triggered it throws the exception, since the listener isn't anymore in the EditText's arraylist.

@JakeWharton
Copy link
Owner

Dupe of #192. This is a platform bug.

@JakeWharton
Copy link
Owner

You can use unsubscribeOn(mainThread()) to work around above take

@lennonpetrick
Copy link
Author

I ain't doing anything in a different thread, so by default it still unregister in the main thread. Anyway, I tried to add unsubscribeOn(mainThread()) as you said, but still happen.

As it's a platform bug, I'll think in a different workaround. Thanks though :)

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

2 participants