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

findViewById, causing missing adapter error #37

Closed
DiogoTheCoder opened this issue Mar 27, 2019 · 6 comments
Closed

findViewById, causing missing adapter error #37

DiogoTheCoder opened this issue Mar 27, 2019 · 6 comments

Comments

@DiogoTheCoder
Copy link

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?

@tommybuonomo
Copy link
Owner

Hi @DiogoTheCoder,
You have to set an adapter to the view pager before setting the view pager to the dots indicator.

@DiogoTheCoder
Copy link
Author

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);

@tommybuonomo
Copy link
Owner

Are you sure that your dailyNutrientsInsightsPageAdapter is not null at this point ?

@DiogoTheCoder
Copy link
Author

Just checked and according to the debugger, it isn't equal to null.

image

@DiogoTheCoder DiogoTheCoder changed the title findViewById, casing missing adapter error findViewById, causing missing adapter error Apr 2, 2019
@tommybuonomo
Copy link
Owner

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.

@Selidinok
Copy link

I have similar issue. DotsIndicator call refreshDots() inside init(AttributeSet attrs) method when class initialize. So even viewPager = null at that moment.

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