Two errors appear in the code:

Cannot resolve method setSupportActionbar Cannot resolve method getSupportFragmentManager() 

Imported android.support.v7.widget.Toolbar but nothing comes out. Here is the code:

 import android.app.Activity; import android.support.design.widget.TabLayout; import android.support.design.widget.FloatingActionButton; import android.support.design.widget.Snackbar; import android.support.v7.app.AppCompatActivity; import android.support.v7.widget.Toolbar; import android.support.v4.app.Fragment; import android.support.v4.app.FragmentManager; import android.support.v4.app.FragmentPagerAdapter; import android.support.v4.view.ViewPager; import android.os.Bundle; import android.view.LayoutInflater; import android.view.Menu; import android.view.MenuItem; import android.view.View; import android.view.ViewGroup; import android.support.v7.widget.Toolbar; import android.widget.TextView; public class MainActivity extends Activity { /** * The {@link android.support.v4.view.PagerAdapter} that will provide * fragments for each of the sections. We use a * {@link FragmentPagerAdapter} derivative, which will keep every * loaded fragment in memory. If this becomes too memory intensive, it * may be best to switch to a * {@link android.support.v4.app.FragmentStatePagerAdapter}. */ private SectionsPagerAdapter mSectionsPagerAdapter; /** * The {@link ViewPager} that will host the section contents. */ private ViewPager mViewPager; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar); setSupportActionBar(toolbar);**<<<<Ошибка здесь** // Create the adapter that will return a fragment for each of the three // primary sections of the activity. mSectionsPagerAdapter = new SectionsPagerAdapter(getSupportFragmentManager());**<<<<Ошибка здесь** 

    1 answer 1

    In order for the setSupportActionBar() and getSupportActionBar() methods to be available to you, you must inherit from AppCompatActivity or its derivatives.


    Just change the class line to:

     public class MainActivity extends AppCompatActivity { ... } 
    • Everything works, thank you!! - Anton