Android Application closing unexpectedly while tabbed fragments swipe -
i have fragment activity contains 3 fragments 1) dayfragment 2) weekfragment 3) monthfragment when swipe first fragment application getting closed , giving exception android.support.v4.app.fragmentmanagerimpl.movetostate(fragmentmanager.java:953)
repeatremainderfragmentactivity.java fragment activity
public class repeatremainderfragmentactivity extends fragmentactivity implements actionbar.tablistener { private viewpager viewpager; private tabspageradapter madapter; private actionbar actionbar; // tab titles private string[] tabs = { "day", "week", "month" }; @override protected void oncreate(bundle savedinstancestate) { super.oncreate(savedinstancestate); setcontentview(r.layout.activity_repeat_fragment); // initilization viewpager = (viewpager) findviewbyid(r.id.pager); actionbar = getactionbar(); madapter = new tabspageradapter(getsupportfragmentmanager()); viewpager.setadapter(madapter); actionbar.sethomebuttonenabled(true); actionbar.setnavigationmode(actionbar.navigation_mode_tabs); // adding tabs (string tab_name : tabs) { actionbar.addtab(actionbar.newtab().settext(tab_name) .settablistener(this)); } /** * on swiping viewpager make respective tab selected * */ viewpager.setonpagechangelistener(new viewpager.onpagechangelistener() { @override public void onpageselected(int position) { // on changing page // make respected tab selected actionbar.setselectednavigationitem(position); } @override public void onpagescrolled(int arg0, float arg1, int arg2) { } @override public void onpagescrollstatechanged(int arg0) { } }); } @override public void ontabreselected(tab tab, fragmenttransaction ft) { } @override public void ontabselected(tab tab, fragmenttransaction ft) { // on tab selected // show respected fragment view viewpager.setcurrentitem(tab.getposition()); } @override public void ontabunselected(tab tab, fragmenttransaction ft) { } }
dayfragment.java
public class dayfragment extends fragment implements onclicklistener, onitemselectedlistener{ private view rootview; @override public view oncreateview(layoutinflater inflater, viewgroup container, bundle savedinstancestate) { rootview = inflater.inflate(r.layout.fragment_day, container, false); initializeui(); setlisteners(); setcurrentdate(); dayrepeatspinner(); return rootview; } private void setcurrentdate() { // todo auto-generated method stub calendar c = calendar.getinstance(); simpledateformat df = new simpledateformat("dd/mm/yyyy"); string formatteddate = df.format(c.gettime()); day_startson_tv.settext(formatteddate); } . . .
weekfragment.java
public class weekfragment extends fragment implements onclicklistener, onitemselectedlistener{ private view rootview; @override public view oncreateview(layoutinflater inflater, viewgroup container, bundle savedinstancestate) { rootview = inflater.inflate(r.layout.fragment_week, container, false); initializeui(); setlisteners(); setcurrentdate(); weekrepeatspinner(); return rootview; } private void setcurrentdate() { // todo auto-generated method stub calendar c = calendar.getinstance(); simpledateformat df = new simpledateformat("dd/mm/yyyy"); string formatteddate = df.format(c.gettime()); week_startson_tv.settext(formatteddate); } private void setlisteners() { // todo auto-generated method stub week_startson_rl.setonclicklistener(this); week_repeatevery_rl.setonclicklistener(this); week_ends_rl.setonclicklistener(this); weekspinner.setonitemselectedlistener(this); sun_tv.setonclicklistener(this); mon_tv.setonclicklistener(this); tue_tv.setonclicklistener(this); wed_tv.setonclicklistener(this); thu_tv.setonclicklistener(this); fri_tv.setonclicklistener(this); sat_tv.setonclicklistener(this); } . . .
monthfragment.java
public class monthfragment extends fragment implements onclicklistener, onitemselectedlistener{ private view rootview; @override public view oncreateview(layoutinflater inflater, viewgroup container, bundle savedinstancestate) { rootview = inflater.inflate(r.layout.fragment_month, container, false); initializeui(); setlisteners(); setcurrentdate(); monthrepeatspinner(); return rootview; } private void setcurrentdate() { // todo auto-generated method stub calendar c = calendar.getinstance(); simpledateformat df = new simpledateformat("dd/mm/yyyy"); string formatteddate = df.format(c.gettime()); month_startson_tv.settext(formatteddate);// showing exception inthis line } private void setlisteners() { // todo auto-generated method stub month_startson_rl.setonclicklistener(this); month_repeatevery_rl.setonclicklistener(this); month_repearby_rl.setonclicklistener(this); month_ends_rl.setonclicklistener(this); monthspinner.setonitemselectedlistener(this); } private void initializeui() { // todo auto-generated method stub month_startson_rl = (relativelayout) rootview.findviewbyid(r.id.month_starton_relativelayout); month_repeatevery_rl = (relativelayout) rootview.findviewbyid(r.id.month_repeat_relativelayout); month_repearby_rl = (relativelayout) rootview.findviewbyid(r.id.month_repeatby_relativelayout); month_ends_rl = (relativelayout) rootview.findviewbyid(r.id.month_ends_relativelayout); monthspinner = (spinner) rootview.findviewbyid(r.id.month_spinner); }
following logcat
04-29 02:27:14.366: e/androidruntime(1499): fatal exception: main 04-29 02:27:14.366: e/androidruntime(1499): process: com.ielts.notes, pid: 1499 04-29 02:27:14.366: e/androidruntime(1499): java.lang.nullpointerexception 04-29 02:27:14.366: e/androidruntime(1499): @ com.ielts.notes.tabswipe.monthfragment.setcurrentdate(monthfragment.java:54) 04-29 02:27:14.366: e/androidruntime(1499): @ com.ielts.notes.tabswipe.monthfragment.oncreateview(monthfragment.java:42) 04-29 02:27:14.366: e/androidruntime(1499): @ android.support.v4.app.fragment.performcreateview(fragment.java:1786) 04-29 02:27:14.366: e/androidruntime(1499): @ android.support.v4.app.fragmentmanagerimpl.movetostate(fragmentmanager.java:953) 04-29 02:27:14.366: e/androidruntime(1499): @ android.support.v4.app.fragmentmanagerimpl.movetostate(fragmentmanager.java:1136) 04-29 02:27:14.366: e/androidruntime(1499): @ android.support.v4.app.backstackrecord.run(backstackrecord.java:739) 04-29 02:27:14.366: e/androidruntime(1499): @ android.support.v4.app.fragmentmanagerimpl.execpendingactions(fragmentmanager.java:1499) 04-29 02:27:14.366: e/androidruntime(1499): @ android.support.v4.app.fragmentmanagerimpl.executependingtransactions(fragmentmanager.java:488) 04-29 02:27:14.366: e/androidruntime(1499): @ android.support.v4.app.fragmentpageradapter.finishupdate(fragmentpageradapter.java:141) 04-29 02:27:14.366: e/androidruntime(1499): @ android.support.v4.view.viewpager.populate(viewpager.java:1073) 04-29 02:27:14.366: e/androidruntime(1499): @ android.support.v4.view.viewpager.populate(viewpager.java:919) 04-29 02:27:14.366: e/androidruntime(1499): @ android.support.v4.view.viewpager$3.run(viewpager.java:249) 04-29 02:27:14.366: e/androidruntime(1499): @ android.view.choreographer$callbackrecord.run(choreographer.java:761) 04-29 02:27:14.366: e/androidruntime(1499): @ android.view.choreographer.docallbacks(choreographer.java:574) 04-29 02:27:14.366: e/androidruntime(1499): @ android.view.choreographer.doframe(choreographer.java:543) 04-29 02:27:14.366: e/androidruntime(1499): @ android.view.choreographer$framedisplayeventreceiver.run(choreographer.java:747) 04-29 02:27:14.366: e/androidruntime(1499): @ android.os.handler.handlecallback(handler.java:733) 04-29 02:27:14.366: e/androidruntime(1499): @ android.os.handler.dispatchmessage(handler.java:95) 04-29 02:27:14.366: e/androidruntime(1499): @ android.os.looper.loop(looper.java:136) 04-29 02:27:14.366: e/androidruntime(1499): @ android.app.activitythread.main(activitythread.java:5017) 04-29 02:27:14.366: e/androidruntime(1499): @ java.lang.reflect.method.invokenative(native method) 04-29 02:27:14.366: e/androidruntime(1499): @ java.lang.reflect.method.invoke(method.java:515) 04-29 02:27:14.366: e/androidruntime(1499): @ com.android.internal.os.zygoteinit$methodandargscaller.run(zygoteinit.java:779) 04-29 02:27:14.366: e/androidruntime(1499): @ com.android.internal.os.zygoteinit.main(zygoteinit.java:595) 04-29 02:27:14.366: e/androidruntime(1499): @ dalvik.system.nativestart.main(native method)
where month_startson_tv
defined? think error like
textview month_startson_tv = (textview)findviewbyid(r.id.month_startson_tv);
is missing, because error message null element, , when textview not defined null , can't set text. use everywhere, should initialize @ top private view rootview;
private textview month_startson_tv;
Comments
Post a Comment