Azoft / CarouselLayoutManager

Android Carousel LayoutManager for RecyclerView
Apache License 2.0
2.56k stars 367 forks source link

Fatal Exception: java.lang.NullPointerException Attempt to read from field 'androidx.recyclerview.widget.RecyclerView$ViewFlinger androidx.recyclerview.widget.RecyclerView.mViewFlinger' on a null object reference #107

Closed Iamkjn22 closed 4 years ago

Iamkjn22 commented 4 years ago

androidx.recyclerview.widget.RecyclerView$SmoothScroller.start (RecyclerView.java:11541) androidx.recyclerview.widget.RecyclerView$LayoutManager.startSmoothScroll (RecyclerView.java:8204) com.azoft.carousellayoutmanager.CarouselLayoutManager.smoothScrollToPosition (CarouselLayoutManager.java:210) androidx.recyclerview.widget.RecyclerView.smoothScrollToPosition (RecyclerView.java:1781) com.juvi.trending.TrendingFragment$2$1.run (TrendingFragment.java:162) java.util.TimerThread.mainLoop (Timer.java:562) java.util.TimerThread.run (Timer.java:512)

mig35 commented 4 years ago

hey @lamkjn22, please check your code - seems like a problem is there or inside RecyclerView. Please check stackoverflow for this issue

Iamkjn22 commented 4 years ago

I checked twice in my code but there is no hint for search this issue can you please help me to rid out of it?

mig35 commented 4 years ago

but I can do nothing too. As I can see the entry point is in TrendingFragment. that calls smoothScrollToPosition. And the crash is inside RecyclerView. So nothing to do in my side.

If you can - debug it and create PR that will fix the issue, I will appreciate this.

Iamkjn22 commented 4 years ago

layoutManager = new CarouselLayoutManager(CarouselLayoutManager.HORIZONTAL, true); layoutManager.setPostLayoutListener(new CarouselZoomPostLayoutListener()); binding.rvCard.setLayoutManager(layoutManager); binding.rvCard.setHasFixedSize(true); binding.rvCard.addOnScrollListener(new CenterScrollListener());

and further, I wrote in api response binding.rvCard.setAdapter(new CardAdapter(getContext(), cardImages));

mig35 commented 4 years ago

Are you sure that you are doing this on the main thread? Again, this is not a library issue, I'm sure.