Android requestFeature() must be called, NOT a Dialog -


first of let me apologize, long post wall of code, wanted thorough.

i error in logcat when click button start fragment in program. it's stating must "requestfeature() before adding content". i've exhausted resources on these forums. went through 16 posts on subject here few show you.

error: requestfeature() must called before adding content - still won't work

"android.util.androidruntimeexception: requestfeature() must called before adding content" on showdialog(dialogid)

dialog problem: requestfeature() must called before adding content

error: "requestfeature() must called before adding content", although called before setcontentview()

none of these solutions worked

the recurring theme these posts seems problem dialogs, custom, action, etc. error occurs when trying launch fragment captures signatures. similar not same.

so here code , logcat.

fragment

public class capturesignature extends fragment {  private static final context context = null; view view; linearlayout mcontent; signature msignature; button mclear, mgetsign, mcancel; public static string tempdir; public int count = 1; public string current = null;    view mview; file mypath;  private string uniqueid; private edittext yourname;  public view oncreateview(layoutinflater inflater, viewgroup container,         bundle savedinstancestate) {      this.getactivity().requestwindowfeature(window.feature_no_title);             view = inflater.inflate(r.layout.fragment_signature, container, false);       mclear = (button) view.findviewbyid(r.id.clear);     mgetsign = (button) view.findviewbyid(r.id.getsign);     mgetsign.setenabled(false);     mcancel = (button) view.findviewbyid(r.id.cancel);     yourname = (edittext) view.findviewbyid(r.id.yourname);      uniqueid = gettodaysdate() + "_" + getcurrenttime() + "_"             + math.random();     current = uniqueid + ".png";      mcontent = (linearlayout) view.findviewbyid(r.id.linearlayout);     msignature = new signature(context, null);     msignature.setbackgroundcolor(color.white);     mcontent.addview(msignature, layoutparams.match_parent,             layoutparams.match_parent);          mview = mcontent;             mclear.setonclicklistener(new onclicklistener() {         public void onclick(view v) {             log.v("log_tag", "panel cleared");             msignature.clear();             mgetsign.setenabled(false);         }     });      mgetsign.setonclicklistener(new onclicklistener() {         public void onclick(view v) {             log.v("log_tag", "panel saved");             boolean error = capturesignature();             if (!error) {                 mview.setdrawingcacheenabled(true);                                                      }         }     });      mcancel.setonclicklistener(new onclicklistener() {         public void onclick(view v) {             log.v("log_tag", "panel canceled");                                  }     });     return view;  }     @override public void ondestroy() {     log.w("getsignature", "ondestory");     super.ondestroy(); }  private boolean capturesignature() {      boolean error = false;     string errormessage = "";      if (yourname.gettext().tostring().equalsignorecase("")) {         errormessage = errormessage + "please enter name\n";         error = true;     }      if (error) {         toast toast = toast                 .maketext(context, errormessage, toast.length_short);         toast.setgravity(gravity.top, 105, 50);         toast.show();     }      return error; }  private string gettodaysdate() {      final calendar c = calendar.getinstance();     int todaysdate = (c.get(calendar.year) * 10000)             + ((c.get(calendar.month) + 1) * 100)             + (c.get(calendar.day_of_month));     log.w("date:", string.valueof(todaysdate));     return (string.valueof(todaysdate));  }  private string getcurrenttime() {      final calendar c = calendar.getinstance();     int currenttime = (c.get(calendar.hour_of_day) * 10000)             + (c.get(calendar.minute) * 100) + (c.get(calendar.second));     log.w("time:", string.valueof(currenttime));     return (string.valueof(currenttime));  }         public class signature extends view {     private static final float stroke_width = 5f;     private static final float half_stroke_width = stroke_width / 2;     private paint paint = new paint();     private path path = new path();      private float lasttouchx;     private float lasttouchy;     private final rectf dirtyrect = new rectf();      public signature(context capturesignature, attributeset attrs) {         super(capturesignature, attrs);         paint.setantialias(true);         paint.setcolor(color.black);         paint.setstyle(paint.style.stroke);         paint.setstrokejoin(paint.join.round);         paint.setstrokewidth(stroke_width);     }        public void clear() {         path.reset();         invalidate();     }      @override     protected void ondraw(canvas canvas) {         canvas.drawpath(path, paint);     }      @override     public boolean ontouchevent(motionevent event) {         float eventx = event.getx();         float eventy = event.gety();         mgetsign.setenabled(true);          switch (event.getaction()) {         case motionevent.action_down:             path.moveto(eventx, eventy);             lasttouchx = eventx;             lasttouchy = eventy;             return true;          case motionevent.action_move:          case motionevent.action_up:              resetdirtyrect(eventx, eventy);             int historysize = event.gethistorysize();             (int = 0; < historysize; i++) {                 float historicalx = event.gethistoricalx(i);                 float historicaly = event.gethistoricaly(i);                 expanddirtyrect(historicalx, historicaly);                 path.lineto(historicalx, historicaly);             }             path.lineto(eventx, eventy);             break;          default:             debug("ignored touch event: " + event.tostring());             return false;         }          invalidate((int) (dirtyrect.left - half_stroke_width),                 (int) (dirtyrect.top - half_stroke_width),                 (int) (dirtyrect.right + half_stroke_width),                 (int) (dirtyrect.bottom + half_stroke_width));          lasttouchx = eventx;         lasttouchy = eventy;          return true;     }      private void debug(string string) {     }      private void expanddirtyrect(float historicalx, float historicaly) {         if (historicalx < dirtyrect.left) {             dirtyrect.left = historicalx;         } else if (historicalx > dirtyrect.right) {             dirtyrect.right = historicalx;         }          if (historicaly < dirtyrect.top) {             dirtyrect.top = historicaly;         } else if (historicaly > dirtyrect.bottom) {             dirtyrect.bottom = historicaly;         }     }      private void resetdirtyrect(float eventx, float eventy) {         dirtyrect.left = math.min(lasttouchx, eventx);         dirtyrect.right = math.max(lasttouchx, eventx);         dirtyrect.top = math.min(lasttouchy, eventy);         dirtyrect.bottom = math.max(lasttouchy, eventy);     } } } 

main activity code

public class main extends activity {  tablistener<store_fragment> surveytablistener;   tablistener<store_fragment> assettablistener; tablistener<store_fragment> installtablistener; tablistener<store_fragment> punchtablistener;  @override protected void oncreate(bundle savedinstancestate) {             super.oncreate(savedinstancestate);       this.requestwindowfeature(window.feature_no_title);      setcontentview(r.layout.activity_main);           // instantiate actionbar     actionbar actionbar = getactionbar();     //actionbar.setbackgrounddrawable((getresources()     //.getdrawable(r.drawable.titlebarheader)));     actionbar.setnavigationmode(actionbar.navigation_mode_tabs);     actionbar.settitle("trakflex");     actionbar.setdisplayshowtitleenabled(true);      // set surveytab     tab surveytab = actionbar.newtab();     surveytablistener = new tablistener<store_fragment>(this,             r.id.header_fragment_container, store_fragment.class);           surveytab.settext("survey").setcontentdescription("survey tab")             .settablistener(surveytablistener);     actionbar.addtab(surveytab);      // set assettab     tab assettab = actionbar.newtab();     assettablistener = new tablistener<store_fragment>(this,             r.id.header_fragment_container, store_fragment.class);     assettab.settext("assets").setcontentdescription("assets tab")             .settablistener(assettablistener);     actionbar.addtab(assettab);      // set installtab     tab installtab = actionbar.newtab();     installtablistener = new tablistener<store_fragment>(this,             r.id.header_fragment_container, store_fragment.class);     installtab.settext("install checklist")             .setcontentdescription("install checklist tab")             .settablistener(installtablistener);     actionbar.addtab(installtab);      // set punchtab     tab punchtab = actionbar.newtab();     punchtablistener = new tablistener<store_fragment>(this,             r.id.header_fragment_container, store_fragment.class);     punchtab.settext("punchlist").setcontentdescription("punchlist tab")             .settablistener(punchtablistener);     actionbar.addtab(punchtab);  } 

new logcat

05-13 18:57:19.767: e/androidruntime(8950): fatal exception: main 05-13 18:57:19.767: e/androidruntime(8950): java.lang.runtimeexception: unable start activity componentinfo{com.facilitysolutionsinc.trackflex/com.facilitysolutionsinc.trackflex.main}: java.lang.nullpointerexception 05-13 18:57:19.767: e/androidruntime(8950):     @ android.app.activitythread.performlaunchactivity(activitythread.java:2180) 05-13 18:57:19.767: e/androidruntime(8950):     @ android.app.activitythread.handlelaunchactivity(activitythread.java:2230) 05-13 18:57:19.767: e/androidruntime(8950):     @ android.app.activitythread.access$600(activitythread.java:141) 05-13 18:57:19.767: e/androidruntime(8950):     @ android.app.activitythread$h.handlemessage(activitythread.java:1234) 05-13 18:57:19.767: e/androidruntime(8950):     @ android.os.handler.dispatchmessage(handler.java:99) 05-13 18:57:19.767: e/androidruntime(8950):     @ android.os.looper.loop(looper.java:137) 05-13 18:57:19.767: e/androidruntime(8950):     @ android.app.activitythread.main(activitythread.java:5041) 05-13 18:57:19.767: e/androidruntime(8950):     @ java.lang.reflect.method.invokenative(native method) 05-13 18:57:19.767: e/androidruntime(8950):     @ java.lang.reflect.method.invoke(method.java:511) 05-13 18:57:19.767: e/androidruntime(8950):     @ com.android.internal.os.zygoteinit$methodandargscaller.run(zygoteinit.java:793) 05-13 18:57:19.767: e/androidruntime(8950):     @ com.android.internal.os.zygoteinit.main(zygoteinit.java:560) 05-13 18:57:19.767: e/androidruntime(8950):     @ dalvik.system.nativestart.main(native method) 05-13 18:57:19.767: e/androidruntime(8950): caused by: java.lang.nullpointerexception 05-13 18:57:19.767: e/androidruntime(8950):     @ com.facilitysolutionsinc.trackflex.main.oncreate(main.java:32) 05-13 18:57:19.767: e/androidruntime(8950):     @ android.app.activity.performcreate(activity.java:5104) 05-13 18:57:19.767: e/androidruntime(8950):     @ android.app.instrumentation.callactivityoncreate(instrumentation.java:1080) 05-13 18:57:19.767: e/androidruntime(8950):     @ android.app.activitythread.performlaunchactivity(activitythread.java:2144) 05-13 18:57:19.767: e/androidruntime(8950):     ... 11 more 

if can extremely grateful

you calling requestwindowfeature() oncreateview() of fragment. entirely late. error says, requestfeature() must called before adding content. here, "adding content" refers things setcontentview() on activity or running fragmenttransaction, both of have occurred before oncreateview() of fragment called.


Comments

Popular posts from this blog

c# - DetailsView in ASP.Net - How to add another column on the side/add a control in each row? -

javascript - firefox memory leak -

Trying to import CSV file to a SQL Server database using asp.net and c# - can't find what I'm missing -