Open mycodedstuff opened 6 years ago
+1
I had exactly the same question. This is a minor bug of this library. But you can avoid this simply by adding at least 3 items to PagerAdapter before you set it to HorizontalInfiniteCycleViewPager.
The reason why it crashes and throws a null pointer exception is, in class com.gigamole.infinitecycleviewpager.InfiniteCycleManager Line 313
public PagerAdapter setAdapter(final PagerAdapter adapter) { // If adapter count bigger then 2 need to set InfiniteCyclePagerAdapter if (adapter != null && adapter.getCount() >= MIN_CYCLE_COUNT) { mItemCount = adapter.getCount(); mInfiniteCyclePagerAdapter = new InfiniteCyclePagerAdapter(adapter); mInfiniteCyclePagerAdapter.setOnNotifyDataSetChangedListener(this); return mInfiniteCyclePagerAdapter; } else { if (mInfiniteCyclePagerAdapter != null) { mInfiniteCyclePagerAdapter.setOnNotifyDataSetChangedListener(null); mInfiniteCyclePagerAdapter = null; } return adapter; } }
If you do not have 3(MIN_CYCLE_COUNT) or more items in adapter, the member mInfiniteCyclePagerAdapter will not be created. So when you invoke getRealItem() it crashes.
I came to know about this when I tried to implement auto scroll. Even I tried to implement auto scroll myself using a separate thread but at getRealItem it throws NullPointerException.
Below is the logcat of exception :