android - How to solve "unable to pause activity java.lang.nullpointerexception"? -
android - How to solve "unable to pause activity java.lang.nullpointerexception"? -
i have 4 tabs in activity, , changing them swipe. using 4 fragments, tabs. swipe working perfectly. issue that, in tab1, have list view , every row of list view contain 2 buttons. button click working perfectly. when swiping tab1 tab3, , 1 time again movin tab1, , after clicking on button, showing "unable pause activity java.lang.nullpointerexception". don't know happening. here code of adapter class implementing button click. please help me.
public class storelistviewadapter extends arrayadapter<item> { context context; private arraylist<item> items; private layoutinflater layoutinflater; public storelistviewadapter(context context, int resourceid, arraylist<item> items) { super(context, resourceid, items); this.context = context; this.items = items; layoutinflater = (layoutinflater) context .getsystemservice(context.layout_inflater_service); } @override public view getview(int position, view convertview, viewgroup parent) { entryitem entryitem = (entryitem) item; final button buttonview = (button) view .findviewbyid(r.id.button_view); final button buttonoffline = (button) view .findviewbyid(r.id.button_offline); buttonview.settag(position); buttonview.setonclicklistener(new onclicklistener() { @override public void onclick(view v) { intent = new intent(context, viewbuttonactivity.class); context.startactivity(i); } }); }
hers tabpageradapter:-
public class tabspageradapter extends fragmentpageradapter { public tabspageradapter(fragmentmanager fm) { super(fm); } @override public fragment getitem(int index) { switch (index) { case 0: homecoming new storefragment(); case 1: homecoming new newsfragment(); case 2: homecoming new eventfragment(); case 3: homecoming new contactusfragment(); } homecoming null; } @override public int getcount() { // todo auto-generated method stub homecoming 4; }
here fragment activity:-
public class mainactivity extends sherlockfragmentactivity{ private viewpager viewpager; private actionbar actionbar; tab tab; @override protected void oncreate(bundle savedinstancestate) { settheme(r.style.exampletheme); super.oncreate(savedinstancestate); setcontentview(r.layout.activity_main); actionbar = getsupportactionbar(); fragmentmanager fm = getsupportfragmentmanager(); getsupportactionbar().setnavigationmode(actionbar.navigation_mode_tabs); viewpager = (viewpager) findviewbyid(r.id.pager); viewpager.simpleonpagechangelistener viewpagerlistener = new viewpager.simpleonpagechangelistener() { @override public void onpageselected(int position) { super.onpageselected(position); // find viewpager position actionbar.setselectednavigationitem(position); } }; viewpager.setonpagechangelistener(viewpagerlistener); // locate adapter class called viewpageradapter.java tabspageradapter viewpageradapter = new tabspageradapter(fm); // set view pager adapter viewpager viewpager.setadapter(viewpageradapter); actionbar.tablistener tablistener = new actionbar.tablistener() { @override public void ontabselected(tab tab, fragmenttransaction ft) { // pass position on tab click viewpager viewpager.setcurrentitem(tab.getposition()); } @override public void ontabunselected(tab tab, fragmenttransaction ft) { } @override public void ontabreselected(tab tab, fragmenttransaction ft) { } }; // create first tab tab = actionbar.newtab().settext("store").settablistener(tablistener); actionbar.addtab(tab); // create sec tab tab = actionbar.newtab().settext("news").settablistener(tablistener); actionbar.addtab(tab); // create 3rd tab tab = actionbar.newtab().settext("events").settablistener(tablistener); actionbar.addtab(tab); // create 4th tab tab = actionbar.newtab().settext("contactus") .settablistener(tablistener); actionbar.addtab(tab); }
here fragment class:-
public class storefragment extends sherlocklistfragment { listview listview; arraylist<item> items = new arraylist<item>(); storelistviewadapter adapter; @override public view oncreateview(layoutinflater inflater, viewgroup container, bundle savedinstancestate) { view rootview = inflater.inflate(r.layout.fragment_store, container, false); listview = (listview) rootview.findviewbyid(android.r.id.list); listview.setonitemclicklistener(new onitemclicklistener() { @override public void onitemclick(adapterview<?> arg0, view arg1, int position, long arg3) { } }); homecoming rootview; } @override public void onactivitycreated(bundle savedinstancestate) { super.onactivitycreated(savedinstancestate); items.add(new entryitem(r.drawable.img1, "stuff india", "category:entertainment", "view", "offline","stuff world's biggest gadget , technology lifestyle mag more 25 editions globally. indian edition upholds these international values while showcasing best gadgets , technology available in india.")); items.add(new sectionitem("previous issue")); items.add(new entryitem(r.drawable.img2, "medgate today", "category:sports", "view", "offline","detail description")); items.add(new entryitem(r.drawable.img3, "hwm singapor", "category:news", "view", "offline","detail description")); items.add(new entryitem(r.drawable.img4, "shape singapore", "category:lifestyle", "view", "offline","detail description")); items.add(new entryitem(r.drawable.img5, "the field", "category:entertainment", "view", "offline","detail description")); items.add(new entryitem(r.drawable.img1, "tv times", "category:news", "view", "offline","detail description")); adapter = new storelistviewadapter(getactivity(), r.layout.tab_row_list_entry, items); listview.setadapter(adapter); } public void onviewbuttonclick(view view){ intent = new intent(getactivity(),viewbuttonactivity.class); startactivity(i); }
here logcate error:-
06-23 11:45:11.839: e/androidruntime(3520): fatal exception: main 06-23 11:45:11.839: e/androidruntime(3520): java.lang.runtimeexception: unable pause activity {com.ebizzinfotech.magazineapp/com.ebizzinfotech.magazineapp.mainactivity}: java.lang.nullpointerexception 06-23 11:45:11.839: e/androidruntime(3520): @ android.app.activitythread.performpauseactivity(activitythread.java:2358) 06-23 11:45:11.839: e/androidruntime(3520): @ android.app.activitythread.performpauseactivity(activitythread.java:2315) 06-23 11:45:11.839: e/androidruntime(3520): @ android.app.activitythread.handlepauseactivity(activitythread.java:2295) 06-23 11:45:11.839: e/androidruntime(3520): @ android.app.activitythread.access$1700(activitythread.java:117) 06-23 11:45:11.839: e/androidruntime(3520): @ android.app.activitythread$h.handlemessage(activitythread.java:942) 06-23 11:45:11.839: e/androidruntime(3520): @ android.os.handler.dispatchmessage(handler.java:99) 06-23 11:45:11.839: e/androidruntime(3520): @ android.os.looper.loop(looper.java:130) 06-23 11:45:11.839: e/androidruntime(3520): @ android.app.activitythread.main(activitythread.java:3687) 06-23 11:45:11.839: e/androidruntime(3520): @ java.lang.reflect.method.invokenative(native method) 06-23 11:45:11.839: e/androidruntime(3520): @ java.lang.reflect.method.invoke(method.java:507) 06-23 11:45:11.839: e/androidruntime(3520): @ com.android.internal.os.zygoteinit$methodandargscaller.run(zygoteinit.java:867) 06-23 11:45:11.839: e/androidruntime(3520): @ com.android.internal.os.zygoteinit.main(zygoteinit.java:625) 06-23 11:45:11.839: e/androidruntime(3520): @ dalvik.system.nativestart.main(native method) 06-23 11:45:11.839: e/androidruntime(3520): caused by: java.lang.nullpointerexception 06-23 11:45:11.839: e/androidruntime(3520): @ android.support.v4.app.fragmentmanagerimpl.savefragmentbasicstate(fragmentmanager.java:1576) 06-23 11:45:11.839: e/androidruntime(3520): @ android.support.v4.app.fragmentmanagerimpl.saveallstate(fragmentmanager.java:1617) 06-23 11:45:11.839: e/androidruntime(3520): @ android.support.v4.app.fragmentactivity.onsaveinstancestate(fragmentactivity.java:481) 06-23 11:45:11.839: e/androidruntime(3520): @ com.actionbarsherlock.app.sherlockfragmentactivity.onsaveinstancestate(sherlockfragmentactivity.java:126) 06-23 11:45:11.839: e/androidruntime(3520): @ android.app.activity.performsaveinstancestate(activity.java:1037) 06-23 11:45:11.839: e/androidruntime(3520): @ android.app.instrumentation.callactivityonsaveinstancestate(instrumentation.java:1181) 06-23 11:45:11.839: e/androidruntime(3520): @ android.app.activitythread.performpauseactivity(activitythread.java:2340) 06-23 11:45:11.839: e/androidruntime(3520): ... 12 more
i sloved problem. @shayan pourvatan helps me. posting solution helping others. giving error because of actionbarsherlock compatibility library. workaround adapter extends fragmentstatepageradapter instead of fragmentpageradapter.
android listview tabs actionbarsherlock
Comments
Post a Comment