Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

Android Android Fragments Managing Fragments Adding the ViewPager

Muhammad Ali
Muhammad Ali
7,192 Points

FragmentPageAdapter with Android.App.Fragment

I am using Android.App.Fragment with ViewPager. The FragmentPagerAdapter constructor expects Android.Support.V4.App.FragmentManager. But the Fragment class ChildFragmentManager is Android.App.Fragment Manager

4 Answers

Seth Kroger
Seth Kroger
56,413 Points

A version of FragmentPageAdapter that usable with non-support fragments is available in the v13 support library. You will need to include the library in your gradle file, compile 'com.android.support:support-v13:23.2.1' If you're using it with a ChildFragmentManager the minSdk needs to be 17 or higher.

http://stackoverflow.com/questions/13501424/fragmentpageradapter-exists-only-in-android-support-v4-app-and-not-android-app

http://stackoverflow.com/questions/17553374/android-app-fragments-vs-android-support-v4-app-using-viewpager?rq=1

can u provide import statement i tried it but still getting same error. i think it must be wrong with import statement.

Abhinav Kanoria
Abhinav Kanoria
7,730 Points

Do I need to use the import statement 'import android.support.v13.app.FragmentPagerAdapter;' instead of 'import android.support.v4.app.FragmentPagerAdapter;' ?? Only when I use the v13 version, I am able to use the method getChildFragmentManager() as a parameter in FragmentPagerAdapter().

Please reply fast!

compile 'com.android.support:support-v13:23.2.1'

does not work for me I still get the same error, my min sdk is 19.

Seth Kroger
Seth Kroger
56,413 Points

Did you replace the import statement in the code?

chandrashekhar singh
chandrashekhar singh
507 Points

java.lang.NullPointerException: Attempt to invoke virtual method 'void android.support.v4.view.ViewPager.setAdapter(android.support.v4.view.PagerAdapter)' on a null object reference i am getting this problem. I need help please.

Yes, it did work for me. Thank you!

can you provide me import statement?

Seth Kroger
Seth Kroger
56,413 Points

import android.support.v13.app.FragmentPagerAdapter;

It should replace the import statement for the v4 support version of that class, if any.