java - Android can't load FragmentActivity from MainActivity -


i'm following google android tutorial basic feel of how apps created can't figure out how implement tabbed menu bar on action menu. following, first set of tutorials, can create basic input form , load inputted text new activity. tried create new button , link activity tutorial below. it's exact copy of google's example

https://developer.android.com/training/implementing-navigation/lateral.html

here manifest file. have original main activity, form input , demo activity contains action bar tabbed menu

    <activity         android:name=".mainactivity"         android:label="@string/app_name" >         <intent-filter>             <action android:name="android.intent.action.main" />              <category android:name="android.intent.category.launcher" />         </intent-filter>     </activity>     <activity         android:name=".displaymessageactivity"         android:label="@string/title_activity_display_message"         android:parentactivityname=".mainactivity" >         <meta-data             android:name="android.support.parent_activity"             android:value="com.francismitra.myapplication.mainactivity" />     </activity>     <activity         android:name=".demoactivity"         android:label="@string/demo_fragment" />     <activity         android:name=".collectiondemoactivity"         android:label="@string/demo_collection" />     <activity 

i launch demo activity main activity through following (this results in app force closing)

public void opendemo(view view) {     intent intent = new intent(this, demoactivity.class);     startactivity(intent); } 

the demoactivity.java file exact copy android developer examples -- updated package names. collectiondemoactivity exact copy. i've confirmed button attached opendemo works setting test activity , launches fine. app closes try open demoactivity.

can explain why can't open specific activity? i'm trying implement design main activity has no action bar tabs , activity can accessed main activity have action bar tabs

public class demoactivity extends fragmentactivity implements actionbar.tablistener {  appsectionspageradapter mappsectionspageradapter; viewpager mviewpager;  @override public void oncreate(bundle savedinstancestate) {     super.oncreate(savedinstancestate);     setcontentview(r.layout.article_view);      // create adapter return fragment each of 3 primary sections     // of app.     mappsectionspageradapter = new appsectionspageradapter(getsupportfragmentmanager());      // set action bar.     final actionbar actionbar = getactionbar();      // specify home/up button should not enabled, since there no hierarchical     // parent.     actionbar.sethomebuttonenabled(false);      // specify displaying tabs in action bar.     actionbar.setnavigationmode(actionbar.navigation_mode_tabs);      // set viewpager, attaching adapter , setting listener when     // user swipes between sections.     mviewpager = (viewpager) findviewbyid(r.id.pager);     mviewpager.setadapter(mappsectionspageradapter);     mviewpager.setonpagechangelistener(new viewpager.simpleonpagechangelistener() {         @override         public void onpageselected(int position) {             // when swiping between different app sections, select corresponding tab.             // can use actionbar.tab#select() if have reference             // tab.             actionbar.setselectednavigationitem(position);         }     });      // each of sections in app, add tab action bar.     (int = 0; < mappsectionspageradapter.getcount(); i++) {         // create tab text corresponding page title defined adapter.         // specify activity object, implements tablistener interface,         // listener when tab selected.         actionbar.addtab(                 actionbar.newtab()                         .settext(mappsectionspageradapter.getpagetitle(i))                         .settablistener(this));     } }'     /**  * fragment launches other parts of demo application.  */ public static class launchpadsectionfragment extends fragment {      @override     public view oncreateview(layoutinflater inflater, viewgroup container,                              bundle savedinstancestate) {         view rootview = inflater.inflate(r.layout.fragment_section_launchpad, container, false);          // demonstration of collection-browsing activity.         rootview.findviewbyid(r.id.demo_collection_button)                 .setonclicklistener(new view.onclicklistener() {                     @override                     public void onclick(view view) {                         intent intent = new intent(getactivity(), collectiondemoactivity.class);                         startactivity(intent);                     }                 });          // demonstration of navigating external activities.         rootview.findviewbyid(r.id.demo_external_activity)                 .setonclicklistener(new view.onclicklistener() {                     @override                     public void onclick(view view) {                         // create intent asks user pick photo, using                         // flag_activity_clear_when_task_reset, ensures relaunching                         // application device home screen not return                         // external activity.                         intent externalactivityintent = new intent(intent.action_pick);                         externalactivityintent.settype("image/*");                         externalactivityintent.addflags(                                 intent.flag_activity_clear_when_task_reset);                         startactivity(externalactivityintent);                     }                 });          return rootview;     } }  /**  * dummy fragment representing section of app, displays dummy text.  */ public static class dummysectionfragment extends fragment {      public static final string arg_section_number = "section_number";      @override     public view oncreateview(layoutinflater inflater, viewgroup container,                              bundle savedinstancestate) {         view rootview = inflater.inflate(r.layout.fragment_section_dummy, container, false);         bundle args = getarguments();         ((textview) rootview.findviewbyid(android.r.id.text1)).settext(                 getstring(r.string.dummy_section_text, args.getint(arg_section_number)));         return rootview;     } } }  } 

here logs:

ddmlib: broken pipe java.io.ioexception: broken pipe     @ sun.nio.ch.filedispatcherimpl.write0(native method)     @ sun.nio.ch.socketdispatcher.write(socketdispatcher.java:47)     @ sun.nio.ch.ioutil.writefromnativebuffer(ioutil.java:93)     @ sun.nio.ch.ioutil.write(ioutil.java:65)     @ sun.nio.ch.socketchannelimpl.write(socketchannelimpl.java:487)     @ com.android.ddmlib.jdwppacket.writeandconsume(jdwppacket.java:213)     @ com.android.ddmlib.client.sendandconsume(client.java:675)     @ com.android.ddmlib.handleheap.sendreaq(handleheap.java:342)     @ com.android.ddmlib.client.requestallocationstatus(client.java:521)     @ com.android.ddmlib.devicemonitor.createclient(devicemonitor.java:847)     @ com.android.ddmlib.devicemonitor.openclient(devicemonitor.java:815)     @ com.android.ddmlib.devicemonitor.processincomingjdwpdata(devicemonitor.java:775)     @ com.android.ddmlib.devicemonitor.deviceclientmonitorloop(devicemonitor.java:664)     @ com.android.ddmlib.devicemonitor.access$100(devicemonitor.java:46)     @ com.android.ddmlib.devicemonitor$3.run(devicemonitor.java:592) 

try this,

public void opendemo(view view) { intent intent = new intent(mainactivity.this, demoactivity.class); startactivity(intent); 

}

remove/ comment other functionality causes crash , follow link: check link


Comments

Popular posts from this blog

yii2 - Yii 2 Running a Cron in the basic template -

asp.net - 'System.Web.HttpContext' does not contain a definition for 'GetOwinContext' Mystery -

mercurial graft feature, can it copy? -