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

getRealItem throws NullPointerException #61

Open
mycodedstuff opened this issue Jan 5, 2018 · 2 comments
Open

getRealItem throws NullPointerException #61

mycodedstuff opened this issue Jan 5, 2018 · 2 comments

Comments

@mycodedstuff
Copy link

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 :

java.lang.NullPointerException
                               at com.gigamole.infinitecycleviewpager.InfiniteCycleManager.getRealItem(InfiniteCycleManager.java:370)
                               at com.gigamole.infinitecycleviewpager.HorizontalInfiniteCycleViewPager.getRealItem(HorizontalInfiniteCycleViewPager.java:226)
                               at in.sabstore.HomeActivity$5$1.run(HomeActivity.java:409)
@srfaytkn
Copy link

srfaytkn commented Apr 1, 2018

+1

@hongwei-bai
Copy link

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.

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

No branches or pull requests

3 participants