android - Fragment crashes when resume to mainactivity -
i have main activity , 4 fragments.i using method ft.replace(r.id.listfragment, myfragment);
switch between fragments in main activity. 1 of fragment (fragment a) contains list view , iam using array adapter fill data listview. problem is, when select "fragment a" visible , listview shown normal. when press home button , resume application app crashes. , error because of array adapter in "fragment a". providing logcat , "fragment a".thanks in advance.any appreciated...
07-24 14:00:12.695: e/androidruntime(25771): fatal exception: main 07-24 14:00:12.695: e/androidruntime(25771): java.lang.nullpointerexception 07-24 14:00:12.695: e/androidruntime(25771): @ android.widget.arrayadapter.init(arrayadapter.java:310) 07-24 14:00:12.695: e/androidruntime(25771): @ android.widget.arrayadapter.<init>(arrayadapter.java:128) 07-24 14:00:12.695: e/androidruntime(25771): @ com.glamzapp.saloon.appoinadapter.<init>(appoinadapter.java:47) 07-24 14:00:12.695: e/androidruntime(25771): @ com.glamzapp.saloon.fragment_appointments$getappointments.onpostexecute(fragment_appointments.java:192) 07-24 14:00:12.695: e/androidruntime(25771): @ com.glamzapp.saloon.fragment_appointments$getappointments.onpostexecute(fragment_appointments.java:1) 07-24 14:00:12.695: e/androidruntime(25771): @ android.os.asynctask.finish(asynctask.java:631) 07-24 14:00:12.695: e/androidruntime(25771): @ android.os.asynctask.access$600(asynctask.java:177) 07-24 14:00:12.695: e/androidruntime(25771): @ android.os.asynctask$internalhandler.handlemessage(asynctask.java:644) 07-24 14:00:12.695: e/androidruntime(25771): @ android.os.handler.dispatchmessage(handler.java:99) 07-24 14:00:12.695: e/androidruntime(25771): @ android.os.looper.loop(looper.java:137) 07-24 14:00:12.695: e/androidruntime(25771): @ android.app.activitythread.main(activitythread.java:5306) 07-24 14:00:12.695: e/androidruntime(25771): @ java.lang.reflect.method.invokenative(native method) 07-24 14:00:12.695: e/androidruntime(25771): @ java.lang.reflect.method.invoke(method.java:511) 07-24 14:00:12.695: e/androidruntime(25771): @ com.android.internal.os.zygoteinit$methodandargscaller.run(zygoteinit.java:1102) 07-24 14:00:12.695: e/androidruntime(25771): @ com.android.internal.os.zygoteinit.main(zygoteinit.java:869) 07-24 14:00:12.695: e/androidruntime(25771): @ dalvik.system.nativestart.main(native method)
code:
public class fragment_appointments extends org.holoeverywhere.app.fragment { listview list; int orderdate_flag = 1; public static string[] customer = { "christian bale", "megan fox", "bradpitt", "christian bale", "megan fox", "bradpitt" }; public static string[] treatment = { "golden facial", "chocolate manicure", "face massage", "golden facial", "chocolate manicure", "face massage" }; public static string[] specialist = { "jacob", "joseline", "linda", "jacob", "joseline", "linda" }; public static string[] date = { "20 feb", "21 feb", "21 feb", "20 feb", "21 feb", "21 feb" }; public static string[] status = { "completed", "not completed", "not completed", "completed", "not completed", "not completed" }; public static string[] timeslot = { "12pm-1pm", "12pm-1pm", "1pm-2pm", "12pm-1pm", "12pm-1pm", "1pm-2pm" }; public static string[] customerimage = { "http://shpintv.com/images/2013/05/christian-bale-wallpapers-.jpg", "http://cdn-media.hollywood.com/images/l/meganfox_620_092812.jpg", "http://www.topnews.in/light/files/brad-pitt_49.jpg", "http://shpintv.com/images/2013/05/christian-bale-wallpapers-.jpg", "http://cdn-media.hollywood.com/images/l/meganfox_620_092812.jpg", "http://www.topnews.in/light/files/brad-pitt_49.jpg" }; public static string[] customer_id = { ",1", "2", "3", "1", "2", "3" }; public static string[] spec_id = { ",1", "2", "3", "1", "2", "3" }; // public static string[] // mast_custname={"all","megan fox","christian bale","bradpitt"}; // public static string[] // mast_specialistname={"all","megan fox","christian bale","bradpitt"}; public static string[] mast_custid = { "1", "2", "3" }; public static string[] mast_specialid = { "1", "2", "3" }; public static string[] mast_status = { "all", "completed", "not completed" }; public static string[] mast_treatment = { "all", "golden facial", "chocolate manicure", "face massage" }; public static string speckey = "0", custkey = "0", statuskey = "0", treatkey = "0"; progressbar progress; static arraylist<string> mast_custname = new arraylist<string>() { { add("christian bale"); add("megan fox"); add("bradpitt"); } }; static arraylist<string> mast_specialistname = new arraylist<string>() { { add("jacob"); add("joseline"); add("linda"); } }; public view oncreateview(layoutinflater inflater, viewgroup container, bundle savedinstancestate) { // inflating layout view v = inflater.inflate(r.layout.appoin_fragment, container, false); // obtain layout references list = (listview) v.findviewbyid(r.id.arlistview); progress = (progressbar) v.findviewbyid(r.id.arprogressbar); list.setemptyview(v.findviewbyid(r.id.empty)); if (utils.isnetworkavailable(getactivity())) { new getappointments(getactivity()).execute(); } else { alertdialog alertdialog = new alertdialog.builder(getactivity()) .create(); alertdialog.setmessage("no network connection!"); alertdialog.setbutton("ok", new dialoginterface.onclicklistener() { public void onclick(dialoginterface dialog, int which) { // todo add code button here. getactivity().finish(); } }); alertdialog.show(); } return v; } @override public void onactivitycreated(bundle savedinstancestate) { // todo auto-generated method stub super.onactivitycreated(savedinstancestate); } @override public void onviewcreated(view view, bundle savedinstancestate) { super.onviewcreated(view, savedinstancestate); // button reset=(button)findviewbyid(r.id.reset); } public class getappointments extends asynctask<void, integer, void> { public getappointments(activity activity) { this.activity = activity; context = activity; dialog = new progressdialog(context); } /** progress dialog show user backup processing. */ private progressdialog dialog; /** application context. */ private activity activity; private context context; protected void onpreexecute() { // todo auto-generated method stub super.onpreexecute(); } @override protected void doinbackground(void... params) { // todo auto-generated method stub return null; } @override protected void onpostexecute(void result) { // todo auto-generated method stub super.onpostexecute(result); progress.setvisibility(view.gone); appoinadapter adapter = new appoinadapter(getactivity(), customer, treatment, specialist, date, status, timeslot, customerimage); list.setadapter(adapter); list.setonitemclicklistener(new onitemclicklistener() { public void onitemclick(adapterview<?> parent, view view, int position, long id) { intent details = new intent(getactivity(), app_details_activity.class); startactivity(details); } }); } }
and here method used switch fragment in main activity
fm = getsupportfragmentmanager(); ft = fm.begintransaction(); fragmenttransaction ft = mainactivity.fm.begintransaction(); fragment_appointments app = new fragment_appointments(); ft.replace(r.id.listfragment, app); ft.commit();
in onpostexecute methods use getactivity().
even if method executed on main thread of application (the uithread), there no guaranty activity created @ instant.
indeed if application restart asynctask onpostexecute called when activity still in indeterminate state or null
Comments
Post a Comment