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 Blog Reader Android App Rebuilding from Scratch Creating the Project and ListActivity

Shariq Shaikh
Shariq Shaikh
13,945 Points

The getSupportFragmentManager is not a public method of ListActivity

As I was following along the video for this particular task of the Blog reader project, we were instructed to change the super class Activity to ListActivity. As a consequence the caused the method getSupportFragmentManager() to be undefined for MainListActivity. In the ADT bundle Ben has been working, doesn't deal with fragments, but I cannot be the only one that has to deal with this issue. Could someone point to either:

A) Create a blank project that does not utilize fragments B) Find a work around for the undefined method

Shariq Shaikh
Shariq Shaikh
13,945 Points

This is not the first problem I have come across with the blog reader app project due to the inconsistencies of the videos and updates made to the sdk and adt plugin

5 Answers

Ben Jakuben
STAFF
Ben Jakuben
Treehouse Teacher

Ugh. This is a really frustrating issue. I actually hadn't realized that the latest version of ADT did this by default now. It's been like this in Android Studio for a while.

The easiest workaround is probably to just download the project files from the link on the page and go from there.

Otherwise you can either remove the fragment code or proceed with it included. If you leave it, most of the work we do occurs within the Fragment instead of the Activity. That seems like it would be confusing to follow, though.

So, to revert to a fragment-free project, you can do the following:

1) Copy all the contents of res/layout/fragment_main_list.xml. Open activity_main.xml, delete the FrameLayout, and paste in the copied contents.

2) Delete fragment_main_list.xml

3) In MainListActivity.java, delete the whole PlaceHolderFragment class:

    /**
     * A placeholder fragment containing a simple view.
     */
    public static class PlaceholderFragment extends Fragment {

        public PlaceholderFragment() {
        }

        @Override
        public View onCreateView(LayoutInflater inflater, ViewGroup container,
                Bundle savedInstanceState) {
            View rootView = inflater.inflate(R.layout.fragment_main_list,
                    container, false);
            return rootView;
        }
    }

4) Delete the following lines from onCreate():

        if (savedInstanceState == null) {
            getSupportFragmentManager().beginTransaction()
                    .add(R.id.container, new PlaceholderFragment()).commit();
        }

That should sync you up with the project in the video.

Longer term, I need to either record a fix for this video or refresh the whole thing sooner than planned.

Erin Kabbash
Erin Kabbash
5,210 Points

I am using the project files and getting an error 'Unable to resolve target 'android-17'

HOW TO FIX: Instead of using the downloadable files, just build the project according to the video and then follow Ben's instructions above. It will fix the problem!

Very frustrating considering we are paying for these lessons. I understand the tools are ever changing but seems like I run into an issue every lesson that takes a very long time to solve. Suggestion: in the teachers notes maybe put like a giant red exclamation point if there is a common error that will prevent the lesson in the video from working completely. Or maybe something in the first 5 seconds of the video alerting users about the issue and inform them to look at the teacher's notes. Just a thought..

However, the issue is resolved and I will continue on! Thanks for your help Ben.

Erin the 'Unable to resolve target 'android-17' is a common issue in Eclipse when importing existing projects. This issue is resolved by selecting "New -> Project" instead of using import functionality in Eclipse. After the new project Wizard shows up, you have to select "Android -> Android Project from Existing Code" menu. Then choose the proper root directory from which you're importing and click "Finish". Then your importing from others people projects or Team Treehouse should be no problem.

Hope this help.

Thanks all for the help.

May 11th video is now updated, thanks!

Harry James
Harry James
14,780 Points

It seems fragments are no longer included now in ADT by default:

Comparison

Infact, if you check your activity_main_list.xml file, you will find that the code which should be in the fragment is already over in this file with the only difference being the context on line 9. This is fine to leave as is. You can change it to how it is on the project as well. Either way, it will make no difference.

Just thought I would include this here to make it clear that you can just carry on with the project as normal even though the fragment option is no longer visible.