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 Understanding the Rest of the Pieces

Viraj Thakur
Viraj Thakur
5,911 Points

No ToolBar

i am building the app on android studio and the app works fine it navigates through the tabs and the tabs are also displayed but the ToolBar (the Activity name and the logout menu item) is not getting displayed i tried many ways but always get an error.

Ben Deitch
Ben Deitch
Treehouse Teacher

Please post the error

please post the error, or fully document what you have tried.

1 Answer

Viraj Thakur
Viraj Thakur
5,911 Points

i have commented the line which cause error

public class MainActivity extends FragmentActivity
implements ActionBar.TabListener {

    private SectionsPagerAdapter mSectionsPagerAdapter;

    private ViewPager mViewPager;

    public static final String TAG = MainActivity.class.getSimpleName();


 @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        ParseUser currentUser = ParseUser.getCurrentUser();

        if (currentUser == null) {
            navigateToLogin();
        } else {
            Log.i(TAG, currentUser.getUsername());
        }

        android.support.v7.widget.Toolbar toolbar = (android.support.v7.widget.Toolbar) findViewById(R.id.toolbar);
        setSupportActionBar(toolbar);                            // error cannot resolve symbol method setSupportActionBar()
        getSupportActionBar().setDisplayHomeAsUpEnabled(true); // error cannot resolve symbol method setSupportActionBar()


        mSectionsPagerAdapter = new SectionsPagerAdapter(this, getSupportFragmentManager());

        mViewPager = (ViewPager) findViewById(R.id.container);
        mViewPager.setAdapter(mSectionsPagerAdapter);

        TabLayout tabLayout = (TabLayout) findViewById(R.id.tabs);
        tabLayout.setupWithViewPager(mViewPager);
    }
}