findViewById, causing missing adapter error
DiogoTheCoder opened this issue · 6 comments
When I execute DotsIndicator dotsIndicator = findViewById(R.id.dots_indicator_view_pager_insights);
, getting an error message straight away
DotsIndicator: You have to set an adapter to the view pager before !
I do set the adapter right after the findViewById
, shouldn't the message appear later on, if no adapter has yet been set?
Hi @DiogoTheCoder,
You have to set an adapter to the view pager before setting the view pager to the dots indicator.
Hi @tommybuonomo
I believe I am currently setting the adapter to the view pager first, then the dots indicator.
Example:
DotsIndicator dailyNutrientsInsightsDotsIndicator = findViewById(R.id.dots_indicator_view_pager_nutrients_insights);
dailyNutrientsInsightsViewPager.setAdapter(dailyNutrientsInsightsPageAdapter);
dailyNutrientsInsightsDotsIndicator.setViewPager(dailyNutrientsInsightsViewPager);
Are you sure that your dailyNutrientsInsightsPageAdapter
is not null at this point ?
Sorry but the code is clear:
if (viewPager != null && viewPager.getAdapter() != null) {
...
} else {
Log.e(DotsIndicator.class.getSimpleName(), "You have to set an adapter to the view pager before !");
}
You have an error somewhere in your code.
I have similar issue. DotsIndicator call refreshDots() inside init(AttributeSet attrs) method when class initialize. So even viewPager = null at that moment.