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

NullPointerException #23

Open
ahmed3elshaer opened this issue Mar 27, 2018 · 12 comments
Open

NullPointerException #23

ahmed3elshaer opened this issue Mar 27, 2018 · 12 comments

Comments

@ahmed3elshaer
Copy link

i just integrated the library and i got this Error on launching the app

FATAL EXCEPTION: main Process: com.wadeeny.ondemand, PID: 20144 java.lang.NullPointerException: Attempt to invoke virtual method 'boolean android.view.View.isNestedScrollingEnabled()' on a null object reference at android.support.v4.view.ViewCompat$ViewCompatApi21Impl.isNestedScrollingEnabled(ViewCompat.java:1320) at android.support.v4.view.ViewCompat.isNestedScrollingEnabled(ViewCompat.java:3308) at biz.laenger.android.vpbs.ViewPagerBottomSheetBehavior.findScrollingChild(ViewPagerBottomSheetBehavior.java:609) at biz.laenger.android.vpbs.ViewPagerBottomSheetBehavior.findScrollingChild(ViewPagerBottomSheetBehavior.java:615) at biz.laenger.android.vpbs.ViewPagerBottomSheetBehavior.findScrollingChild(ViewPagerBottomSheetBehavior.java:622) at biz.laenger.android.vpbs.ViewPagerBottomSheetBehavior.onLayoutChild(ViewPagerBottomSheetBehavior.java:252) at android.support.design.widget.CoordinatorLayout.onLayout(CoordinatorLayout.java:894) at android.view.View.layout(View.java:19590) at android.view.ViewGroup.layout(ViewGroup.java:6053) at android.support.v4.widget.DrawerLayout.onLayout(DrawerLayout.java:1171) at android.view.View.layout(View.java:19590) at android.view.ViewGroup.layout(ViewGroup.java:6053) at android.widget.FrameLayout.layoutChildren(FrameLayout.java:323) at android.widget.FrameLayout.onLayout(FrameLayout.java:261) at android.view.View.layout(View.java:19590) at android.view.ViewGroup.layout(ViewGroup.java:6053) at android.widget.FrameLayout.layoutChildren(FrameLayout.java:323) at android.widget.FrameLayout.onLayout(FrameLayout.java:261) at android.view.View.layout(View.java:19590) at android.view.ViewGroup.layout(ViewGroup.java:6053) at android.widget.LinearLayout.setChildFrame(LinearLayout.java:1791) at android.widget.LinearLayout.layoutVertical(LinearLayout.java:1635) at android.widget.LinearLayout.onLayout(LinearLayout.java:1544) at android.view.View.layout(View.java:19590) at android.view.ViewGroup.layout(ViewGroup.java:6053) at android.widget.FrameLayout.layoutChildren(FrameLayout.java:323) at android.widget.FrameLayout.onLayout(FrameLayout.java:261) at android.view.View.layout(View.java:19590) at android.view.ViewGroup.layout(ViewGroup.java:6053) at android.widget.LinearLayout.setChildFrame(LinearLayout.java:1791) at android.widget.LinearLayout.layoutVertical(LinearLayout.java:1635) at android.widget.LinearLayout.onLayout(LinearLayout.java:1544) at android.view.View.layout(View.java:19590) at android.view.ViewGroup.layout(ViewGroup.java:6053) at android.widget.FrameLayout.layoutChildren(FrameLayout.java:323) at android.widget.FrameLayout.onLayout(FrameLayout.java:261) at com.android.internal.policy.DecorView.onLayout(DecorView.java:758) at android.view.View.layout(View.java:19590) at android.view.ViewGroup.layout(ViewGroup.java:6053) at android.view.ViewRootImpl.performLayout(ViewRootImpl.java:2488) at android.view.ViewRootImpl.performTraversals(ViewRootImpl.java:2204) at android.view.ViewRootImpl.doTraversal(ViewRootImpl.java:1390) at android.view.ViewRootImpl$TraversalRunnable.run(ViewRootImpl.java:6754) at android.view.Choreographer$CallbackRecord.run(Choreographer.java:966) at android.view.Choreographer.doCallbacks(Choreographer.java:778) at android.view.Choreographer.doFrame(Choreographer.java:713) at android.view.Choreographer$FrameDisplayEventReceiver.run(Choreographer.java:952) at android.os.Handler.handleCallback(Handler.java:789) at android.os.Handler.dispatchMessage(Handler.java:98) at android.os.Looper.loop(Looper.java:172) at android.app.ActivityThread.main(ActivityThread.java:6637) at java.lang.reflect.Method.invoke(Native Method) at com.android.internal.os.Zygote$MethodAndArgsCaller.run(Zygote.java:240) at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:767)

@hynra
Copy link

hynra commented Apr 4, 2018

Wrap your ViewPager with NestedScrollView:

<android.support.v4.widget.NestedScrollView
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:fillViewport="true"
            app:layout_behavior="@string/appbar_scrolling_view_behavior">

            <android.support.v4.view.ViewPager
                android:id="@+id/bottom_sheet_viewpager"
                android:layout_width="match_parent"
                android:layout_height="match_parent" />
        </android.support.v4.widget.NestedScrollView>

@gcobc12632
Copy link

@hynra
this can avoid the exception.
but my listview in ViewPagerBottomSheet can't scroll anymore.

@laenger
Copy link
Owner

laenger commented Apr 18, 2018

Is this reproducible with (corresponding adjustments inside) the example app from this repository?

@huzaifaiftikhar
Copy link

@laenger I'm also getting the same issue. If I use the same layout in the example app it works. However in my app it crashes with this error. If I remove viewpager from my layout the app doesn't crash. However on adding the viewpager it crashes!
I'm trying to integrate your library in Open Food Facts android app.

@laenger
Copy link
Owner

laenger commented Jun 7, 2018

Looking at this again, it seems that #24 fixed this.

@huzaifaiftikhar
Copy link

huzaifaiftikhar commented Jun 7, 2018

I tried this fix already before it was merged. It seems to fix the error since we do a null check however the viewpager doesn't scroll anymore. If I try to scroll down the bottom sheet collapses. Maybe I am doing something wrong. Please help!

@laenger
Copy link
Owner

laenger commented Jun 14, 2018

Again, without a minimal reproducible example, it is very difficult to dig deeper into this. It would be great if you could modify the example app such that it runs into the described issue.

@danponce
Copy link

I was having the same crash and it was because I wasn't adding any fragment to the view pager. Be sure to check that you're adding some fragment to the view pager so it can initiate right

@jobburg
Copy link

jobburg commented Aug 3, 2018

I have the same problem and a reprodcution path. You need to use a PagerAdapter instead of a FragmentPagerAdapter to reproduce it.

@daniellAlgar
Copy link

I was also having this problem. I solved it by adding android:nestedScrollingEnabled="true" to my ViewPager.

@beelancrp
Copy link

@daniellAlgar This solution is not correct, because of incorrect work of behavior.
I found a better solution for this bug. Try to use ViewPager.post { BottomSheetUtils.setupViewPager(viewPager) }.

Think it would be helpful. But need to understand how to fix it in lib.

@beelancrp
Copy link

For a better understanding, I show you how I use it.
`
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {super.onViewCreated(view, savedInstanceState)

    pagerAdapter = StoryBoardStatsFragmentPagerAdapter(activity!!.supportFragmentManager)

    if (storyResponse.likedusers.isNotEmpty()) {
        pagerAdapter.addFragment(StoryDetailsTabFragment.newInstance(
                StoryDetailsTabFragment.TabType.LIKES, storyResponse, this),
                storyResponse.likeCount.toString().plus(" likes"))
    }

    if (storyResponse.viewedusers.isNotEmpty()) {
        pagerAdapter.addFragment(StoryDetailsTabFragment.newInstance(
                StoryDetailsTabFragment.TabType.VIEWS, storyResponse, this),
                storyResponse.viewCount.toString().plus(" views"))
    }

    viewPager.offscreenPageLimit = 1
    viewPager.adapter = pagerAdapter

    tabs.setupWithViewPager(viewPager)
}

override fun onDataLoaded() {
    viewPager.post {
        behavior = ViewPagerBottomSheetBehavior.from(container)

        behavior.isHideable = true
        behavior.setBottomSheetCallback(object : ViewPagerBottomSheetBehavior.BottomSheetCallback() {
            override fun onSlide(bottomSheet: View, slideOffset: Float) {
                val percent = slideOffset * 100
                if (percent <= 45 && wasExpanded)
                    behavior.state = ViewPagerBottomSheetBehavior.STATE_HIDDEN
            }

            override fun onStateChanged(bottomSheet: View, newState: Int) {
                if (newState == BottomSheetBehavior.STATE_EXPANDED)
                    wasExpanded = true

                if (newState == BottomSheetBehavior.STATE_HIDDEN)
                    router.clearStackFragment()
            }
        })

        BottomSheetUtils.setupViewPager(viewPager) {
            router.clearStackFragment()
        }
    }
}`

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

No branches or pull requests

9 participants