Skip to content Skip to sidebar Skip to footer

Attempt To Invoke Virtual Method 'void Android.support.v4.view.viewpager.setadapter(android.support.v4.view.pageradapter)' On A Null Object Reference

I'm trying to implement sliding tab layout using android material design. But it gives me NullPointerException. Here is my code so far: MainActivity.java public class MainActivity

Solution 1:

You have your view pager in activity_main.xml while your layout for activity is setContentView(R.layout.activity_main_appbar). You do not have view pager in activity_main_appbar.xml.

findViewById looks for a view in the current view hierarchy. I guess it should be setContentView(R.layout.activity_main); but do check what views you have in included layout app_bar.xml

Solution 2:

It May be you pass an wrong id of viewPager.Please Check your id from XML File

Post a Comment for "Attempt To Invoke Virtual Method 'void Android.support.v4.view.viewpager.setadapter(android.support.v4.view.pageradapter)' On A Null Object Reference"