Looks like you forgot to add the line setContentView(R.layout.yourxml);
it has to be done before calling this, ViewPager pager = (ViewPager) findViewById(R.id.pager);
. If you don't do this, Android doesn't know where to look for the resource and obviously it will return null and that's the reason you are getting NullPointerException I guess.