Search code examples
androideclipsematerial-designandroid-toolbar

Error setting Toolbar as ActionBar


I'm trying to replace the ActionBar of my app with a Toolbar but I can't because I can't use setSupportActionBar(). It says "setSupportActionBar() is undefined for the type MainActivity" even if MainActivity extends ActionBarActivity. I don't know what to do, any help? Do you need me to post my code?

EDIT: Now the code works but my app crashes on start and it says: "Attempt to invoke virtual method getTitle()". What do I miss?

EDIT2: Everything works I forgot I had a Fragment and because of that it gave me nullPointer


Solution

  • Without code, my only recommendation, is making sure your import statement is as follows:

    import android.support.v7.app.ActionBarActivity;
    import android.support.v7.widget.Toolbar;
    

    Also make sure in your XML files that you are using

    <android.support.v7.widget.Toolbar
    

    As your toolbar tag