android - Fragment returning Null context -
i've been trying fix past 2 hours. tried lot of things.
the fragment seems passing null context adapter. have tried initialize context variable in oncreate , oncreateview , onactivitycreated. same result.
here fragment:
public class activebookingsfragment extends fragment { context con; arraylist<booking> bookings; listview activebookings_lv; @override public void oncreate(bundle savedinstancestate) { super.oncreate(savedinstancestate); } @override public void onactivitycreated(bundle savedinstancestate) { super.onactivitycreated(savedinstancestate); con = this.getactivity(); } @override public view oncreateview(layoutinflater inflater, @nullable viewgroup container, @nullable bundle savedinstancestate) { view v =inflater.inflate(r.layout.tab_activebookings,container,false); activebookings_lv = (listview) v.findviewbyid(r.id.lv_activebookings); bookings = new arraylist<booking>(); booking b1 = new booking("data"); bookings.add(b1); activebookings_lv.setadapter(new bookingadapter(con, bookings)); return v; } }
and here logcat error:
java.lang.nullpointerexception @ android.view.layoutinflater.from(layoutinflater.java:212) @ com.nettechltd.cabeecustomer.customadapters.bookingadapter.<init>(bookingadapter.java:26) @ com.nettechltd.cabeecustomer.activebookingsfragment.oncreateview(activebookingsfragment.java:51) @ android.support.v4.app.fragment.performcreateview(fragment.java:1789) @ android.support.v4.app.fragmentmanagerimpl.movetostate(fragmentmanager.java:955) @ android.support.v4.app.fragmentmanagerimpl.movetostate(fragmentmanager.java:1138) @ android.support.v4.app.backstackrecord.run(backstackrecord.java:740) @ android.support.v4.app.fragmentmanagerimpl.execpendingactions(fragmentmanager.java:1501) @ android.support.v4.app.fragmentmanagerimpl.executependingtransactions(fragmentmanager.java:490) @ android.support.v4.app.fragmentstatepageradapter.finishupdate(fragmentstatepageradapter.java:163) @ android.support.v4.view.viewpager.populate(viewpager.java:1105) @ android.support.v4.view.viewpager.populate(viewpager.java:951) @ android.support.v4.view.viewpager.onmeasure(viewpager.java:1473) @ android.view.view.measure(view.java:17633) @ android.view.viewgroup.measurechildwithmargins(viewgroup.java:5428) @ android.widget.linearlayout.measurechildbeforelayout(linearlayout.java:1413) @ android.widget.linearlayout.measurevertical(linearlayout.java:696) @ android.widget.linearlayout.onmeasure(linearlayout.java:589) @ android.view.view.measure(view.java:17633) @ android.view.viewgroup.measurechildwithmargins(viewgroup.java:5428) @ android.widget.framelayout.onmeasure(framelayout.java:310) @ android.support.v7.internal.widget.contentframelayout.onmeasure(contentframelayout.java:124) @ android.view.view.measure(view.java:17633) @ android.view.viewgroup.measurechildwithmargins(viewgroup.java:5428) @ android.widget.linearlayout.measurechildbeforelayout(linearlayout.java:1413) @ android.widget.linearlayout.measurevertical(linearlayout.java:696) @ android.widget.linearlayout.onmeasure(linearlayout.java:589) @ android.view.view.measure(view.java:17633) @ android.view.viewgroup.measurechildwithmargins(viewgroup.java:5428) @ android.widget.framelayout.onmeasure(framelayout.java:310) @ android.view.view.measure(view.java:17633) @ android.view.viewgroup.measurechildwithmargins(viewgroup.java:5428) @ android.widget.linearlayout.measurechildbeforelayout(linearlayout.java:1413) @ android.widget.linearlayout.measurevertical(linearlayout.java:696) @ android.widget.linearlayout.onmeasure(linearlayout.java:589) @ android.view.view.measure(view.java:17633) @ android.view.viewgroup.measurechildwithmargins(viewgroup.java:5428) @ android.widget.framelayout.onmeasure(framelayout.java:310) @ com.android.internal.policy.impl.phonewindow$decorview.onmeasure(phonewindow.java:2588) @ android.view.view.measure(view.java:17633) @ android.view.viewrootimpl.performmeasure(viewrootimpl.java:2347) @ android.view.viewrootimpl.measurehierarchy(viewrootimpl.java:1439) @ android.view.viewrootimpl.performtraversals(viewrootimpl.java:1653) @ android.view.viewrootimpl.dotraversal(viewrootimpl.java:1297) @ android.view.viewrootimpl$traversalrunnable.run(viewrootimpl.java:6773) @ android.view.choreographer$callbackrecord.run(choreographer.java:813) @ android.view.choreographer.docallbacks(choreographer.java:613) @ android.view.choreographer.doframe(choreographer.java:583) @ android.view.choreographer$framedisplayeventreceiver.run(choreographer.java:799) @ android.os.handler.handlecallback(handler.java:733) @ android.os.handler.dispatchmessage(handler.java:95) @ android.os.looper.loop(looper.java:146) @ android.app.activitythread.main(activitythread.java:5748) @ java.lang.reflect.method.invokenative(native method) @ java.lang.reflect.method.invoke(method.java:515) @ com.android.internal.os.zygoteinit$methodandargscaller.run(zygoteinit.java:1291) @ com.android.internal.os.zygotein
initialize context
in fragment onattach(.....)
like
@override public void onattach(activity activity) { super.onattach(activity); con = getactivity(); } }
Comments
Post a Comment