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![](https://ecs-static.teamtreehouse.com/assets/views/marketing/shared/community-banner-white-47072046c51352fe6a69f5e691ff5700b28bb11d45197d7bdf066d9ea3f72d0c.webp)
![Sexual Potatoes](https://uploads.teamtreehouse.com/production/profile-photos/3964122/micro_hacker6.jpg)
Sexual Potatoes
12,051 PointsgetChildFragmentManager() not being accepted
Whenever I try to use it, Android Studio says "FragmentPageAdapter in FragmentPageAdapter cannot be applied to android.app.FragmentManager.
I have followed the instructions of other questions that asked users to add a few things to their gradle file and none of them worked. The video seems to be outdated and with no notes. What should I do to get through this part?
6 Answers
![Jason Anders](https://uploads.teamtreehouse.com/production/profile-photos/3512822/micro_Jason_s-Pic.jpg)
Jason Anders
Treehouse Moderator 145,859 PointsWithout seeing all your code, it's very tough to help troubleshoot.
However, I just completed that section of the course this afternoon, and I had no issues. I am using the most current version of Android Studio, and all my files and dependencies are up-to-date, so I don't think the video is outdated. So, it sounds like you may have imported something wrong.
I would go over the last few videos, and make sure everything is imported correctly. (eg. you have android.support.v4.app.Fragment
instead of just Fragment
).
If you still can't find your error, you can download the project files for the video, which should bring you up to speed to where he is in the Video.
Hope you get it solved. :)
![Stephen Wall](https://uploads.teamtreehouse.com/production/profile-photos/5591242/micro_11050676_10153547952002082_3934335435538405651_n.jpg)
Stephen Wall
Courses Plus Student 27,294 PointsMake sure your ViewPagerFragment class extends "android.support.v4.app.Fragmet", and not just "Fragment".
![Boban Talevski](https://secure.gravatar.com/avatar/4ac9cd657eb3140becd88637010f570d?s=96&d=https%3A%2F%2Fecs-static.teamtreehouse.com%2Fassets%2Fcontent%2Fdefault_avatar-445fbbabfc8dc9188fb5967fe43322ee0c3e0dd1e10f378bf8343784af5a13eb.webp&r=pg)
Boban Talevski
24,793 Points@Rohan Tilekar. You should follow what Ben does in the video Managing the Back Stack to make all your Fragments extend from the v4 support library version of the Fragment class, along with FragmentManager and FragmentTransaction classes. There's also a change in the getFragmentManager method and you should use getSupportFragmentManager instead.
I got myself in the same confusing situation after leaving the Fragment classes as initially imported from the native Fragment class, which worked fine for the functionality of addToBackStack method as it didn't need the fix as in the video above. But at this point in the course, I'm setting them to be imported from the v4 support version because it seems the least confusing way to complete the course.
We need this because of the use of ViewPager and the FragmentPagerAdapter which are requiring the use of the v4 support version of the Fragment class as well. As someone mentioned above, you could extend the v13 support library version of the FragmentPagerAdapter class which allows the use of the native Fragment class, but then you would have to increase the minimum SDK of the project to 17 because it's required by the getChildFragmentManager method.
So all in all, it seems it's best to follow the video instructions even though the teacher notes at the above video say that the issue Ben presents in the video is already solved which suggests we don't need to make the change at that point in the course. But at this point, I think it's best to do so.
![Stephen Wall](https://uploads.teamtreehouse.com/production/profile-photos/5591242/micro_11050676_10153547952002082_3934335435538405651_n.jpg)
Stephen Wall
Courses Plus Student 27,294 PointsActually I was a bit hasty on my answer. I had to actually raise the min SDK version of my project to 17 in the build.gradle file (Module: app).
Then under dependencies, add the line: compile 'com.android.support:support-v13:+'
Then in your ViewPagerFragment.java file, when you are setting the adapter, make sure you are using the correct version of the FragmentPagerAdapter:
ViewPager viewPager = (ViewPager) view.findViewById(R.id.viewPager);
viewPager.setAdapter(new android.support.v13.app.FragmentPagerAdapter(getChildFragmentManager()) {
@Override
public Fragment getItem(int position) {
return position == 09 ? ingredientsFragment : directionsFragment;
}
Finally, within your IngredientsFragment.java file and your DirectionsFragment.java file, be sure to extend: android.app.Fragment
public class IngredientsFragment extends android.app.Fragment
![Sam Kennedy](https://secure.gravatar.com/avatar/87b3147228c5a1a1fc75300c837db26a?s=96&d=https%3A%2F%2Fecs-static.teamtreehouse.com%2Fassets%2Fcontent%2Fdefault_avatar-445fbbabfc8dc9188fb5967fe43322ee0c3e0dd1e10f378bf8343784af5a13eb.webp&r=pg)
Sam Kennedy
2,449 PointsWhen I use just Fragment, I get an error on the line:
fragmentTransaction.replace(R.id.placeholder, viewPagerFragment, VIEWPAGER_FRAGMENT);
saying that viewPagerFragment should be of type android.app.Fragment instead. When importing just Fragment this error goes away but of course I then get the error Lucas has.
![Rohan Tilekar](https://secure.gravatar.com/avatar/9a5e06bf5a64de9ca1877b4eee3a2481?s=96&d=https%3A%2F%2Fecs-static.teamtreehouse.com%2Fassets%2Fcontent%2Fdefault_avatar-445fbbabfc8dc9188fb5967fe43322ee0c3e0dd1e10f378bf8343784af5a13eb.webp&r=pg)
Rohan Tilekar
134 Points- My Ingredients and Directions fragments extend Fragment. 2.My MainActivity extends import android.app.FragmentManager; 3.The below code is ViewPagerFragment. this code // public Fragment getItem(int position) { // Fragment shows error.
getItem() , says is incompatible return type. What is the problem?
import android.support.v4.app.FragmentPagerAdapter; import android.support.v4.view.ViewPager; import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; import android.widget.Toast;
/**
- Created by rohan on 9/23/17. */
public class ViewPagerFragment extends Fragment { public static final String KEY_RECIPE_INDEX= "recipe_index";
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
int index = getArguments().getInt(KEY_RECIPE_INDEX);
Toast.makeText(getActivity(),Recipe.names[index],Toast.LENGTH_SHORT).show();
final IngrediantsFragment ingrediantsFragment = new IngrediantsFragment();
final DirectionsFragment directionsFragment = new DirectionsFragment();
View view = inflater.inflate(R.layout.fragment_viewpager,container,false);
ViewPager viewPager = (ViewPager)view.findViewById(R.id.viewpager);
viewPager.setAdapter(new FragmentPagerAdapter(getChildFragmentManager()) {
@Override
public Fragment getItem(int position) {
if(position == 0)
{
return ingrediantsFragment;
}
else
return directionsFragment;
}
@Override
public int getCount() {
Sexual Potatoes
12,051 PointsSexual Potatoes
12,051 PointsHi, Jason, you hit the nail on the head, the problem was that my class extended Fragment and not android.support.v4.app.Fragment !