1. Error as follows:
2. Causes of errors:
The problems caused by the first situation:
Solution: in inflate (R.l ayout layout2, Container), should be changed to inflate (R.l ayout. Layout2, null); Actually the best written inflate (R.l ayout layout2, container, false); So this is a good way to write it;
The second situation causes problems:
Viewpager1 is not in the activity_main1 layout;
@Override
protected void onCreate(@Nullable Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main1);
ViewPager mViewPager = findViewById(R.id.viewpager1);
Copy the code
Solutions:
ViewPager mViewPager = findViewById(R.id.viewpager1); Reference ViewPager in the layout where viewPager1 resides;