laenger / ViewPagerBottomSheet

Use ViewPagers in Bottom Sheets!
Apache License 2.0
465 stars 86 forks source link

Null Pointer Exception #16

Closed avinashbanswada closed 7 years ago

avinashbanswada commented 7 years ago

Hello,I am getting NPE when changing the device font to Gothic Bold or device language to Gujrati with maximum font size applied. Device : Samsung Galaxy On8 OS Version : Lollipop

Please help me out in fixing this. After debugging I got to know the view is becoming null in this line "View scrollingChild = this.findScrollingChild((View)this.mViewRef.get());" which is in ViewPagerBottomSheetBehaviour class. How to null check the view here?

java.lang.NullPointerException: Attempt to invoke virtual method 'java.lang.Object java.lang.ref.WeakReference.get()' on a null object reference at biz.laenger.android.vpbs.ViewPagerBottomSheetBehavior.invalidateScrollingChild(ViewPagerBottomSheetBehavior.java:433) at biz.laenger.android.vpbs.BottomSheetUtils$BottomSheetViewPagerListener$1.run(BottomSheetUtils.java:32) at android.os.Handler.handleCallback(Handler.java:739) at android.os.Handler.dispatchMessage(Handler.java:95) at android.os.Looper.loop(Looper.java:148) at android.app.ActivityThread.main(ActivityThread.java:7402) at java.lang.reflect.Method.invoke(Native Method) at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1230) at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1120)

laenger commented 7 years ago

at which point do you call BottomSheetUtils.setupViewPager(viewPager) in your app? can you provide a minimal snippet of your activity/fragment initialization?

avinashbanswada commented 7 years ago

In onViewCreated() of fragment we are initializing . Here is the snippet

public void onViewCreated(View view, @Nullable Bundle savedInstanceState) { super.onViewCreated(view, savedInstanceState); mTabsAdapter = new TabsAdapter(getChildFragmentManager(), getContext()); mViewPager.setAdapter(mTabsAdapter); TabLayout mTabLayout = new Tablayout......; mTabLayout.setupWithViewPager(mViewPager); BottomSheetUtils.setupViewPager(mViewPager); }

laenger commented 7 years ago

unfortunately i don't have that device to reproduce this error

avinashbanswada commented 7 years ago

Got fixed by moving the bottom sheet view pager initialization to onResume() which is "BottomSheetUtils.setupViewPager(mViewPager);" so that every time the page is loaded the bottom sheet is reinitialize.