java - Why am I getting this error? Please see the details -
i'm developing material design app & applying activity transition have written following code in mainactivity.java
my mainactivity.java
file's 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 >= build.version_codes.lollipop) { // call 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 request"); tabone.settypeface(tf); tablayout.gettabat(0).setcustomview(tabone); textview tabtwo = (textview) layoutinflater.from(this).inflate(r.layout.custom_tab, null); tabtwo.settext("post request"); tabtwo.settypeface(tf); tablayout.gettabat(1).setcustomview(tabtwo); } private void setupviewpager(viewpager viewpager) { viewpageradapter adapter = new viewpageradapter(getsupportfragmentmanager()); adapter.addfragment(new acceptarequest(), "accept request"); adapter.addfragment(new postarequest(), "post request"); viewpager.setadapter(adapter); } class viewpageradapter extends fragmentpageradapter { private final list<fragment> mfragmentlist = new arraylist<>(); private final list<string> mfragmenttitlelist = new arraylist<>(); 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 menu; adds items action bar if present. getmenuinflater().inflate(r.menu.menu_main, menu); return true; } @override public boolean onoptionsitemselected(menuitem item) { // handle action bar item clicks here. action bar // automatically handle clicks on home/up button, long // specify 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 >= build.version_codes.lollipop) { // call material design apis here getwindow().setexittransition(new explode()); intent profileintent = new intent(mainactivity.this, profileactivity.class); startactivity(profileintent, activityoptions .makescenetransitionanimation(this).tobundle()); } else { // implement 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 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); } }
after running app, i'm getting following error:
android.util.androidruntimeexception: requestfeature() must called before adding content must called before adding content.
i not understand why getting error when have added requestfeature()
before adding content?
please let me know.
i'm new stackoverflow, please cooperate.
thanks in advance.
your activity extends appcompatactivity
extensive setup in oncreate()
. call requestfeature()
before calling super.oncreate()
.
Comments
Post a Comment