java - No view found for id for fragment PlaceholderFragment -


i created main activity, sends me activiteresultats activity.

my goal show message in activity (message come main).

i followed starting activity tutorial.

the problem is, when start activiteresultats activity, have error:

"no view found id 0x7f080000 ........... fragment placeholderfragment"

... , app shuts down.

i don't know yet how use fragments, , tutorial says don't have use example.

where going wrong?

my code :

package com.example.surveyor;  import android.app.activity; import android.app.fragment; 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.widget.textview;  public class activiteresultats extends activity {  @override protected void oncreate(bundle savedinstancestate) {     super.oncreate(savedinstancestate);     setcontentview(r.layout.activity_activite_resultats);      if (savedinstancestate == null) {         getfragmentmanager().begintransaction()                 .add(r.id.container, new     placeholderfragment()).commit();     }       string message = "todo";      // create text view     textview textview = new textview(this);     textview.settextsize(40);     textview.settext(message);      // set text view activity layout     setcontentview(textview);   }    @override public boolean oncreateoptionsmenu(menu menu) {      // inflate menu; adds items action bar if present.     getmenuinflater().inflate(r.menu.activite_resultats, 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();     if (id == r.id.action_settings) {         return true;     }     return super.onoptionsitemselected(item); }  /**  * placeholder fragment containing simple view.  */ public static class placeholderfragment extends fragment {      public placeholderfragment() {     }      @override     public view oncreateview(layoutinflater inflater, viewgroup container,             bundle savedinstancestate) {         view rootview = inflater.inflate(                 r.layout.fragment_activite_resultats, container, false);         return rootview;     } }  } 

i had same problem. remove part:

if (savedinstancestate == null) { getfragmentmanager().begintransaction()                     .add(r.id.container, new placeholderfragment()).commit();         } 

that solved me. hope helps!


Comments

Popular posts from this blog

user interface - How to replace the Python logo in a Tkinter-based Python GUI app? -

objective c - Greedy NSProgressIndicator Allocation -

how to set an OCR language in Google Drive -