android - Content view not yet created -
i trying retrieve data mysql , sort based on category tab. application crash when open activity content view not yet created. may know problem?
03-10 04:12:49.043: e/androidruntime(2251): fatal exception: main 03-10 04:12:49.043: e/androidruntime(2251): java.lang.runtimeexception: unable start activity componentinfo{my.fyp.inticlassifieds/my.fyp.inticlassifieds.displaypostitem}: java.lang.illegalstateexception: content view not yet created 03-10 04:12:49.043: e/androidruntime(2251): @ android.app.activitythread.performlaunchactivity(activitythread.java:2211) 03-10 04:12:49.043: e/androidruntime(2251): @ android.app.activitythread.handlelaunchactivity(activitythread.java:2261) 03-10 04:12:49.043: e/androidruntime(2251): @ android.app.activitythread.access$600(activitythread.java:141) 03-10 04:12:49.043: e/androidruntime(2251): @ android.app.activitythread$h.handlemessage(activitythread.java:1256) 03-10 04:12:49.043: e/androidruntime(2251): @ android.os.handler.dispatchmessage(handler.java:99) 03-10 04:12:49.043: e/androidruntime(2251): @ android.os.looper.loop(looper.java:137) 03-10 04:12:49.043: e/androidruntime(2251): @ android.app.activitythread.main(activitythread.java:5103) 03-10 04:12:49.043: e/androidruntime(2251): @ java.lang.reflect.method.invokenative(native method) 03-10 04:12:49.043: e/androidruntime(2251): @ java.lang.reflect.method.invoke(method.java:525) 03-10 04:12:49.043: e/androidruntime(2251): @ com.android.internal.os.zygoteinit$methodandargscaller.run(zygoteinit.java:737) 03-10 04:12:49.043: e/androidruntime(2251): @ com.android.internal.os.zygoteinit.main(zygoteinit.java:553) 03-10 04:12:49.043: e/androidruntime(2251): @ dalvik.system.nativestart.main(native method) 03-10 04:12:49.043: e/androidruntime(2251): caused by: java.lang.illegalstateexception: content view not yet created 03-10 04:12:49.043: e/androidruntime(2251): @ android.support.v4.app.listfragment.ensurelist(listfragment.java:328) 03-10 04:12:49.043: e/androidruntime(2251): @ android.support.v4.app.listfragment.getlistview(listfragment.java:222) 03-10 04:12:49.043: e/androidruntime(2251): @ my.fyp.inticlassifieds.booksfragment.oncreateview(booksfragment.java:87) 03-10 04:12:49.043: e/androidruntime(2251): @ android.support.v4.app.fragment.performcreateview(fragment.java:1500) 03-10 04:12:49.043: e/androidruntime(2251): @ android.support.v4.app.fragmentmanagerimpl.movetostate(fragmentmanager.java:927) 03-10 04:12:49.043: e/androidruntime(2251): @ android.support.v4.app.fragmentmanagerimpl.movetostate(fragmentmanager.java:1104) 03-10 04:12:49.043: e/androidruntime(2251): @ android.support.v4.app.backstackrecord.run(backstackrecord.java:682) 03-10 04:12:49.043: e/androidruntime(2251): @ android.support.v4.app.fragmentmanagerimpl.execpendingactions(fragmentmanager.java:1467) 03-10 04:12:49.043: e/androidruntime(2251): @ android.support.v4.app.fragmentactivity.onstart(fragmentactivity.java:570) 03-10 04:12:49.043: e/androidruntime(2251): @ android.app.instrumentation.callactivityonstart(instrumentation.java:1171) 03-10 04:12:49.043: e/androidruntime(2251): @ android.app.activity.performstart(activity.java:5143) 03-10 04:12:49.043: e/androidruntime(2251): @ android.app.activitythread.performlaunchactivity(activitythread.java:2184) 03-10 04:12:49.043: e/androidruntime(2251): ... 11 more
class:
public class booksfragment extends listfragment { // progress dialog private progressdialog pdialog; // creating json parser object jsonparser jparser = new jsonparser(); jsonobject json; arraylist<products> productslist = new arraylist<products>(); // url products list private static string url_all_products = "http://10.0.2.2:8000/project/display_items.php"; // json node names private static final string tag_success = "success"; private static final string tag_products = "product"; private static final string tag_pid = "pid"; private static final string tag_name = "name"; private static final string tag_budget = "price"; private static final string tag_des = "description"; private static final string tag_date_posted = "created_at"; private static final string tag_category = "category"; private static final string tag_email = "email"; private static final string tag_contact = "contact"; // products jsonarray jsonarray products = null; listview lv; listadapter listadapter; @override public view oncreateview(layoutinflater inflater, viewgroup container, bundle savedinstancestate) { view rootview = inflater.inflate(r.layout.list_fragment, container, false); productslist = new arraylist<products>(); lv = getlistview(); // on seleting single product // launching edit product screen lv.setonitemclicklistener(new onitemclicklistener() { @override public void onitemclick(adapterview<?> parent, view view, int position, long id) { // getting values selected listitem string pid = ((textview) view.findviewbyid(r.id.pid)).gettext() .tostring(); string name = ((textview) view.findviewbyid(r.id.name)) .gettext().tostring(); string description = ((textview) view.findviewbyid(r.id.des)) .gettext().tostring(); string price = ((textview) view.findviewbyid(r.id.budget)) .gettext().tostring(); string date = ((textview) view.findviewbyid(r.id.date_posted)) .gettext().tostring(); string category = ((textview) view.findviewbyid(r.id.category)) .gettext().tostring(); string email = ((textview) view .findviewbyid(r.id.email_request)).gettext().tostring(); string contact = ((textview) view .findviewbyid(r.id.contact_request)).gettext() .tostring(); // starting new intent intent in = new intent(getactivity(), displayiteminfo.class); // sending information next activity in.putextra(tag_pid, pid); in.putextra(tag_name, name); in.putextra(tag_des, description); in.putextra(tag_budget, price); in.putextra(tag_date_posted, date); in.putextra(tag_category, category); in.putextra(tag_email, email); in.putextra(tag_contact, contact); startactivity(in); } }); new loadallproducts().execute(); return rootview; } class loadallproducts extends asynctask<string, string, string> { /** * before starting background thread show progress dialog * */ @override protected void onpreexecute() { super.onpreexecute(); pdialog = new progressdialog(getactivity()); pdialog.setmessage("loading products. please wait..."); pdialog.setindeterminate(false); pdialog.setcancelable(false); pdialog.show(); } /** * getting products url * */ protected string doinbackground(string... args) { // building parameters list<namevaluepair> params = new arraylist<namevaluepair>(); intent intent = getintent(); // getting attached intent data string jsons = intent.getstringextra("json"); if (jsons == null) { // getting json string url json = jparser.makehttprequest(url_all_products, "get", params); } else { try { jsonobject jsonobj = new jsonobject(jsons); json = jsonobj; } catch (jsonexception e) { // todo auto-generated catch block e.printstacktrace(); } } // check log cat json reponse log.d("all products: ", json.tostring()); try { // checking success tag int success = json.getint(tag_success); if (success == 1) { // products found // getting array of products products = json.getjsonarray(tag_products); // looping through products (int = 0; < products.length(); i++) { jsonobject c = products.getjsonobject(i); // storing each json item in variable string id = c.getstring(tag_pid); string name = c.getstring(tag_name); string budget = c.getstring(tag_budget); string description = c.getstring(tag_des); string category = c.getstring(tag_category); string contact = c.getstring(tag_contact); string email = c.getstring(tag_email); string date = c.getstring(tag_date_posted); if (category == "books") { // create new product obect, set values products mproduct = new products(); mproduct.pid = id; mproduct.name = name; mproduct.price = budget; mproduct.description = description; mproduct.date = date; mproduct.category = category; mproduct.email = email; mproduct.contact = contact; // adding product arraylist productslist.add(mproduct); } } } else { // no products found // launch add new product activity intent = new intent(getactivity(), mainmenu.class); // closing previous activities i.addflags(intent.flag_activity_clear_top); startactivity(i); } } catch (jsonexception e) { e.printstacktrace(); } return null; } private intent getintent() { // todo auto-generated method stub return null; } /** * after completing background task dismiss progress dialog * **/ protected void onpostexecute(string file_url) { // dismiss dialog after getting products pdialog.dismiss(); if (productslist.size() > 0) { /** * updating parsed json data listview * */ customadapter adapter = new customadapter(getactivity(), productslist);// , if (getlistview() != null) { // updating listview setlistadapter(adapter); } else { log.d("listview-reference", "listview null"); } } else { log.d("product list", "products list empty"); } } } }
oncreateview
must return view represent fragment. other operations on view should performed in callback, onviewcreated
:
@override public view oncreateview(layoutinflater inflater, viewgroup container, bundle savedinstancestate) { return inflater.inflate(r.layout.list_fragment, container, false); } @override public void onviewcreated (view view, bundle savedinstancestate) { productslist = new arraylist<products>(); lv = getlistview(); // on seleting single product // launching edit product screen lv.setonitemclicklistener(new onitemclicklistener() { @override public void onitemclick(adapterview<?> parent, view view, int position, long id) { // getting values selected listitem string pid = ((textview) view.findviewbyid(r.id.pid)).gettext() .tostring(); string name = ((textview) view.findviewbyid(r.id.name)) .gettext().tostring(); string description = ((textview) view.findviewbyid(r.id.des)) .gettext().tostring(); string price = ((textview) view.findviewbyid(r.id.budget)) .gettext().tostring(); string date = ((textview) view.findviewbyid(r.id.date_posted)) .gettext().tostring(); string category = ((textview) view.findviewbyid(r.id.category)) .gettext().tostring(); string email = ((textview) view .findviewbyid(r.id.email_request)).gettext().tostring(); string contact = ((textview) view .findviewbyid(r.id.contact_request)).gettext() .tostring(); // starting new intent intent in = new intent(getactivity(), displayiteminfo.class); // sending information next activity in.putextra(tag_pid, pid); in.putextra(tag_name, name); in.putextra(tag_des, description); in.putextra(tag_budget, price); in.putextra(tag_date_posted, date); in.putextra(tag_category, category); in.putextra(tag_email, email); in.putextra(tag_contact, contact); startactivity(in); } }); new loadallproducts().execute(); }
Comments
Post a Comment