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 Build a Self-Destructing Message Android App Using Fragments for Tabs Modifying Tabs from the Template

zahir herz
zahir herz
3,513 Points

Android Studio: Incompatible Fragment types

MainActivity.java

Using Android Studio as my IDE and have encountered an issue while attempting to refactor the code. MainActivity.java in Android Studio differs from the code used in the tutorials ie DummyFragment When I attempted to refactor the code in this lesson I was presented with incompatible fragment types. The above link is how my code looks at the start of this lesson. Can someone who has built this project in Android Studio please advise?

3 Answers

zahir herz
zahir herz
3,513 Points

Ended up starting from scratch and using the provided source code for the lesson (sigh) but now everything compiles. Thanks for your help.

Ben Jakuben
STAFF
Ben Jakuben
Treehouse Teacher

The Ribbit app uses a ViewPager to manage the Fragments as tabs. There's a weird thing we talk about in the videos with this. ViewPager is from a support library and is backwards compatible, so we need to use the support versions of Fragments even though we're only targeting newer versions of Android in our project. You need to change your import statements from

import android.app.Fragment;
import android.app.FragmentManager;
import android.app.FragmentTransaction;

to

import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentManager;
import android.support.v4.app.FragmentTransaction;
zahir herz
zahir herz
3,513 Points

When attempting your suggestion receive the following error: Error:(23, 8) com.floatingspace.ribbit.app.MainActivity is not abstract and does not override abstract method onTabReselected(android.app.ActionBar.Tab,android.app.FragmentTransaction) in android.app.ActionBar.TabListener

Guessing my project is pointed to a different version of ActionBar than the one you use in your tutorial? Any suggestions Ben Jakuben ?

Ben Jakuben
Ben Jakuben
Treehouse Teacher

There are three required methods to implement the ActionBar.TabListener. Sounds like the following method might be missing from your MainActivity class:

    @Override
    public void onTabReselected(ActionBar.Tab tab, FragmentTransaction fragmentTransaction) {

    }

Can you paste in your code from MainActivity.java?