Why am I getting this error? Please see the details <p>I'm developing a material design app &amp; for applying activity transition I have written the following code in my <code>MainActivity.java</code></p> <p>My <code>MainActivity.java</code> file's code:</p> <pre><code>public class MainActivity extends AppCompatActivity { public Toolbar toolbar; public TabLayout tabLayout; public ViewPager viewPager; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); if (Build.VERSION.SDK_INT &gt;= Build.VERSION_CODES.LOLLIPOP) { // Call some material design APIs here // enable transitions getWindow().requestFeature(Window.FEATURE_CONTENT_TRANSITIONS); } else { } setContentView(R.layout.activity_main); SpannableString s = new SpannableString("abc"); s.setSpan(new TypefaceSpan(this, "Pacifico.ttf"), 0, s.length(), Spannable.SPAN_EXCLUSIVE_EXCLUSIVE); toolbar = (Toolbar) findViewById(R.id.toolbar); setSupportActionBar(toolbar); getSupportActionBar().setDisplayHomeAsUpEnabled(false); getSupportActionBar().setTitle(s); viewPager = (ViewPager) findViewById(R.id.viewpager); setupViewPager(viewPager); tabLayout = (TabLayout) findViewById(R.id.tabs); tabLayout.setupWithViewPager(viewPager); customTabFont(); } private void customTabFont() { String fontPath = "fonts/Pacifico.ttf"; Typeface tf = Typeface.createFromAsset(getAssets(), fontPath); TextView tabOne = (TextView) LayoutInflater.from(this).inflate(R.layout.custom_tab, null); tabOne.setText("Accept a Request"); tabOne.setTypeface(tf); tabLayout.getTabAt(0).setCustomView(tabOne); TextView tabTwo = (TextView) LayoutInflater.from(this).inflate(R.layout.custom_tab, null); tabTwo.setText("Post a Request"); tabTwo.setTypeface(tf); tabLayout.getTabAt(1).setCustomView(tabTwo); } private void setupViewPager(ViewPager viewPager) { ViewPagerAdapter adapter = new ViewPagerAdapter(getSupportFragmentManager()); adapter.addFragment(new AcceptARequest(), "Accept a Request"); adapter.addFragment(new PostARequest(), "Post a Request"); viewPager.setAdapter(adapter); } class ViewPagerAdapter extends FragmentPagerAdapter { private final List&lt;Fragment&gt; mFragmentList = new ArrayList&lt;&gt;(); private final List&lt;String&gt; mFragmentTitleList = new ArrayList&lt;&gt;(); public ViewPagerAdapter(FragmentManager manager) { super(manager); } @Override public Fragment getItem(int position) { return mFragmentList.get(position); } @Override public int getCount() { return mFragmentList.size(); } public void addFragment(Fragment fragment, String title) { mFragmentList.add(fragment); mFragmentTitleList.add(title); } @Override public CharSequence getPageTitle(int position) { return mFragmentTitleList.get(position); } } @Override public boolean onCreateOptionsMenu(Menu menu) { // Inflate the menu; this adds items to the action bar if it is present. getMenuInflater().inflate(R.menu.menu_main, menu); return true; } @Override public boolean onOptionsItemSelected(MenuItem item) { // Handle action bar item clicks here. The action bar will // automatically handle clicks on the Home/Up button, so long // as you specify a parent activity in AndroidManifest.xml. int id = item.getItemId(); //noinspection SimplifiableIfStatement if (id == R.id.action_profile) { // Check if we're running on Android 5.0 or higher if (Build.VERSION.SDK_INT &gt;= Build.VERSION_CODES.LOLLIPOP) { // Call some material design APIs here getWindow().setExitTransition(new Explode()); Intent profileIntent = new Intent(MainActivity.this, ProfileActivity.class); startActivity(profileIntent, ActivityOptions .makeSceneTransitionAnimation(this).toBundle()); } else { // Implement this feature without material design Intent profileIntent = new Intent(MainActivity.this, ProfileActivity.class); startActivity(profileIntent); } } else if (id == R.id.action_settings) { Intent settingsIntent = new Intent(MainActivity.this, SettingsActivity.class); startActivity(settingsIntent); } else if (id == R.id.action_help) { Intent helpIntent = new Intent(Intent.ACTION_SEND); Intent chooser = Intent.createChooser(helpIntent, "Choose an app"); helpIntent.putExtra(Intent.EXTRA_EMAIL, new String[]{"help@abcxyz123.com"}); helpIntent.setType("message/rfc822"); startActivity(chooser); } else if (id == R.id.action_faqs) { Intent faqsIntent = new Intent(Intent.ACTION_VIEW, Uri.parse("http://www.abcxyz123.com/faqs")); startActivity(faqsIntent); } else if (id == R.id.action_about) { Intent aboutIntent = new Intent(MainActivity.this, AboutActivity.class); startActivity(aboutIntent); } return super.onOptionsItemSelected(item); } } </code></pre> <p>After running the app, I'm getting following error: </p> <pre><code>android.util.AndroidRuntimeException: requestFeature() must be called before adding content must be called before adding content. </code></pre> <p>I do not understand why am I getting this error when I have added the <code>requestFeature()</code> before adding the content?</p> <p>Please let me know.</p> <p>I'm new to StackOverflow, so please cooperate.</p> <p>Thanks in advance.</p>