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

Problem with Incompatible Types: Modifying Fragments from the template video

I have an error on the SectionPagerAdapter java class when i return a new InboxFragment(), the error says "Incompatible types: Required: android.app.Fragment; Found: com.treehouse.ribbit.InboxFragment;".

i guess the problem may be the fact that the InboxFragment is a ListFragment type and the getItem function is looking to return a Fragment type, but isn't the ListFragment a sub-class of Fragment?

3 Answers

Ben Jakuben
STAFF
Ben Jakuben
Treehouse Teacher

This is probably due to the type of Fragment used. android.app.Fragment is the regular type of Fragment. But there is another version that is exactly the same except it has backwards compatibility for older versions of Android: android.support.v4.app.Fragment. We have to use the support versions to use the ViewPager, which is also backwards compatible.

My guess is that your ListFragment import statement in InboxFragment is using the android.app.ListFragment when it should be android.support.v4.app.ListFragment. Delete the import statement and organize your imports and then you should be able to select the support version.

Thanks Ben...that did the job.

Josh Gold
Josh Gold
12,207 Points

In InboxFragment I changed

```public class InboxFragment extends android.app.ListFragment {

to :

```public class InboxFragment extends android.support.v4.app.ListFragment {
```<br><br>
Thanks Ben!