I´m using in my Android (4.0+) app fragment (in Activity) with Tab bar.
I want to create Espresso test but if I create main Activity and open the fragment. I get this Exception:
java.lang.IllegalStateException: ViewPager does not have adapter instance.
at com.astuetz.PagerSlidingTabStrip.setViewPager(PagerSlidingTabStrip.java:177)
at cz.villamemories.detoxme.staticcontent.StaticContentFragment.onCreateView(StaticContentFragment.java:197)
My code in fragment:
@Override
public void onActivityCreated(Bundle savedInstanceState) {
super.onActivityCreated(savedInstanceState);
mViewPagerAdapter = new StaticContentPagerAdapter(
this.getChildFragmentManager(), mItemsList, categories);
mPager.setAdapter(mViewPagerAdapter);
mTabs.setViewPager(mPager); //line 197
Do you have some tip where can be a problem? What is wrong?
I was also facing the issue with ViewPager in fragment. This problem occurs me because of my viewpager has a multiple root elements.
and this is my homefragment.xml file
I hope it may help you to create a test case in Expresso Framework.