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

Library crashes if recyclerview's item's rootview contains "layout_margin" attribute. #9

Closed
mansigoel94 opened this issue Jan 19, 2018 · 10 comments
Labels

Comments

@mansigoel94
Copy link

Library crashes if recyclerview's item's rootview contains "layout_margin" attribute.

Below is the crash log ::

01-19 17:02:50.296 18167-18167/? E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.lrm.emark, PID: 18167
java.lang.RuntimeException: Unable to start activity ComponentInfo{com.lrm.emark/com.lrm.emark.MainActivity}: java.lang.IllegalStateException: An instance of OnFlingListener already set.
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2927)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2988)
at android.app.ActivityThread.-wrap14(ActivityThread.java)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1631)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:154)
at android.app.ActivityThread.main(ActivityThread.java:6682)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1520)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1410)
Caused by: java.lang.IllegalStateException: An instance of OnFlingListener already set.
at android.support.v7.widget.SnapHelper.setupCallbacks(SnapHelper.java:115)
at android.support.v7.widget.SnapHelper.attachToRecyclerView(SnapHelper.java:103)
at com.lrm.emark.feed.FeedbackFragment.onCreateView(FeedbackFragment.java:131)
at android.support.v4.app.Fragment.performCreateView(Fragment.java:2354)
at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:1419)
at android.support.v4.app.FragmentManagerImpl.moveFragmentToExpectedState(FragmentManager.java:1740)
at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:1809)
at android.support.v4.app.BackStackRecord.executeOps(BackStackRecord.java:799)
at android.support.v4.app.FragmentManagerImpl.executeOps(FragmentManager.java:2580)
at android.support.v4.app.FragmentManagerImpl.executeOpsTogether(FragmentManager.java:2367)
at android.support.v4.app.FragmentManagerImpl.removeRedundantOperationsAndExecute(FragmentManager.java:2322)
at android.support.v4.app.FragmentManagerImpl.execPendingActions(FragmentManager.java:2229)
at android.support.v4.app.FragmentManagerImpl.dispatchStateChange(FragmentManager.java:3221)
at android.support.v4.app.FragmentManagerImpl.dispatchActivityCreated(FragmentManager.java:3171)
at android.support.v4.app.FragmentController.dispatchActivityCreated(FragmentController.java:192)
at android.support.v4.app.FragmentActivity.onStart(FragmentActivity.java:560)
at android.support.v7.app.AppCompatActivity.onStart(AppCompatActivity.java:177)
at android.app.Instrumentation.callActivityOnStart(Instrumentation.java:1256)
at android.app.Activity.performStart(Activity.java:6959)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2890)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2988) 
at android.app.ActivityThread.-wrap14(ActivityThread.java) 
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1631) 
at android.os.Handler.dispatchMessage(Handler.java:102) 
at android.os.Looper.loop(Looper.java:154) 
at android.app.ActivityThread.main(ActivityThread.java:6682) 
at java.lang.reflect.Method.invoke(Native Method) 
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1520) 
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1410) 

@rbro112 rbro112 added the bug label Jan 19, 2018
@rbro112
Copy link
Collaborator

rbro112 commented Jan 19, 2018

Great catch, thanks. I'll check this out in depth soon and have a fix before long.

@rbro112
Copy link
Collaborator

rbro112 commented Jan 22, 2018

@mansigoel94 would you mind sending me the XML layout file that is causing the error? I'm trying to recreate this on my side and I am unable to by just setting the recyclerview's root view layout_margin to an arbitrary value.

@mansigoel94
Copy link
Author

mansigoel94 commented Jan 23, 2018

<android.support.constraint.ConstraintLayout
android:layout_width="match_parent"
android:layout_height="match_parent">

    <android.support.v7.widget.RecyclerView
        android:id="@+id/recycler_view"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        **android:layout_margin="8dp"** (here layout largin would not cause any problem)
        app:layout_constraintLeft_toLeftOf="parent"
        app:layout_constraintRight_toRightOf="parent"
      />

    <com.rbrooks.indefinitepagerindicator.IndefinitePagerIndicator
        android:id="@+id/recyclerview_pager_indicator"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginTop="4dp"  (Here also margin would run just fine)
        app:dotColor="@android:color/black"
        app:layout_constraintLeft_toLeftOf="parent"
        app:layout_constraintRight_toRightOf="parent"
        app:layout_constraintTop_toBottomOf="@id/rv_top_search"
        app:selectedDotColor="@color/colorAccent" />

</android.support.constraint.ConstraintLayout>

But in another layout where you define recycler view items then in rootview margin would break code
example:

<android.support.constraint.ConstraintLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="8dp"> (this line would cause code to break.... Also margin_top, margin_bottom and margin_Right would run perfectly, only margin left doesn't)

<ImageView
    android:id="@+id/iv_preview"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:scaleType="fitXY"
    app:layout_constraintEnd_toEndOf="parent" />

</android.support.constraint.ConstraintLayout>

@rbro112
Copy link
Collaborator

rbro112 commented Jan 24, 2018

Unfortunately, I still haven't been able to recreate the bug on my end. I added the layout_margin to both the RecyclerView's rootview and the view item's root view and it still is working normally for me.

Upon further inspection of the stacktrace, it seems that this line is the actual bug:

Caused by: java.lang.IllegalStateException: An instance of OnFlingListener already set.

Are you setting an OnFlingListener in your code where you setup your recyclerview? Or are you calling recyclerView.setOnScrollListener(scrollListener) rather than recyclerView.addOnScollListener(scrollListener)? If so, this could be the issue as it would likely be overriding the IndefinitePagerIndicator's internal onScrollListener that's used to update the indicator.

@rbro112
Copy link
Collaborator

rbro112 commented Feb 5, 2018

@mansigoel94 any update on this? I'm going to close the issue if my comment above is the overall issue.

@mansigoel94
Copy link
Author

No I haven't used any ScrollListener or FlingListener and this error is still reproducible on my machine. I will share sample project with you.

@mansigoel94
Copy link
Author

https://github.com/mansigoel94/Library-Issue.git.
Check this code, I have added one todo for you where 'layout-margin' is causing library to crash

@wching
Copy link
Owner

wching commented Feb 11, 2018

@mansigoel94 based on the code you shared, I can see that you are using version 1.0.3 and indeed the crash happens because null is getting to the RecyclerView's
findContainingItemView(View view) method.

That was fixed by @rbro112 in this commit (line 268):
2311872
which was basically a fix released on version 1.0.4 🎉

So I think the solution to your bug will be updating to the latest version [ current is 1.0.6 ] of the library 😃

@rbro112
Copy link
Collaborator

rbro112 commented Feb 12, 2018

@wching you're killing it! Thanks so much.

That's why I wasn't able to replicate, locally I've been experimenting with the most up to date version of the library. Will be good to know for future reference that often I'll need to drop my versioning down to ensure I'm checking older versions.

@mansigoel94 please let me know if updating to 1.0.6 works!

@rbro112
Copy link
Collaborator

rbro112 commented Feb 21, 2018

Looks like 1.0.6+ is the fix. Closing this issue!

@rbro112 rbro112 closed this as completed Feb 21, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants