turing-tech / MaterialScrollBar

An Android library that brings the Material Design 5.1 sidebar to pre-5.1 devices.
Apache License 2.0
781 stars 126 forks source link

RuntimeException when calling viewGroup.addView(scrollBarView) #90

Open PtiPingouin opened 7 years ago

PtiPingouin commented 7 years ago

I jumped from 12.3.1 to 12.3.5, and now, I get "RuntimeException: Cannot make calls to a recycled instance!" when calling viewGroup.addView(scrollBarView).

java.lang.RuntimeException: Cannot make calls to a recycled instance! at android.content.res.TypedArray.hasValue(TypedArray.java:1008) at com.turingtechnologies.materialscrollbar.MaterialScrollBar.implementPreferences(MaterialScrollBar.java:190) at com.turingtechnologies.materialscrollbar.MaterialScrollBar$2.run(MaterialScrollBar.java:133) at com.turingtechnologies.materialscrollbar.MaterialScrollBar.generalSetup(MaterialScrollBar.java:244) at com.turingtechnologies.materialscrollbar.MaterialScrollBar.onAttachedToWindow(MaterialScrollBar.java:229) at android.view.View.dispatchAttachedToWindow(View.java:15509) at android.view.ViewGroup.dispatchAttachedToWindow(ViewGroup.java:2916) at android.view.ViewGroup.addViewInner(ViewGroup.java:4456) at android.view.ViewGroup.addView(ViewGroup.java:4258) at android.view.ViewGroup.addView(ViewGroup.java:4198)

turing-tech commented 7 years ago

I'm not getting a crash on the example project. Would you mind providing more of the code before and after your addView() call?

PtiPingouin commented 7 years ago

The reason I'm removing / adding back the scrollbar from the viewgroup is because I never was able to just hide it (neither setVisibility(GONE) nor setScrollBarHidden(false) works for me). So the crash occurs after I removed the view once, then simply try to add it back to the same parent. Simple call to View.remove() and View.add(). Nothing fancy here.

qiminl commented 7 years ago

I got this issue as well

chanonly123 commented 7 years ago

Its in MaterialScrollBar.java -> generalSetup() -> a.recycle() causing the crash. Use MaterialScrollBar in xml to bypass this bug.

silent10 commented 7 years ago

I am getting the same error for the same reason!

turing-tech commented 6 years ago

I have gotten several reports of setVisibility(GONE) and setScrollBarHidden(false) not working. However, I myself am unable to replicate them. A code sample from anyone having this issue would be greatly appreciated. I'll even put the lucky winner in the README ;)

ln-12 commented 6 years ago

I'm also having this issue. In my case this always happens, when I want to enter the popup window mode on samsung devices as described here and here. Surprisingly the native Android Multi-Window-Mode (described here) works fine.