Error Toolbar Android, setSupportActionBar,

1

I can not fix the error in setsupporActionBar I tried to change the inheritance from appCompat to Activity and it remains the same. Thank you very much for your time

public class MainActivity extends AppCompatActivity {
    private Toolbar toolbar;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        toolbar = findViewById(R.id.Tool_bar);
        setSupportActionBar(toolbar);
    }
    ...
    
asked by AGOI 27.10.2018 в 11:13
source

1 answer

3

You have the problem in the declaration of setSupporActionBar .

You are declaring a toolbar that comes from android.widget.Toolbar and that type of toolbar can not be assigned to setSupporActionBar .

To solve the error you need to remove the import of android.widget.Toolbar and import android.support.v7.widget.Toolbar which is what you need in this case.

As you can see in the image, it is the error of the one that alerts you to android studio.

    
answered by 27.10.2018 / 12:16
source