android - OnCreateView NullPointerException -


i have app in google play store. getting crash notifications through crashlytics/fabric, don't have true logcat reference. also, unable figure out how replicate bug on own system.

the error i'm getting crashlytics follows:

com.company.appname.fragment.oncreateview (fragment.java:48)

here's pertinent detail class declaration:

import android.support.v4.app.fragment; public class mytypefragment extends fragment {... 

here's code portion of fragment:

44 mrestartbutton = (button)contentview.findviewbyid(r.id.restart_button); 45 mrestartbutton.settypeface(regulartf); 46 mrestartbutton.setonclicklistener(new view.onclicklistener() { 47     @override 48     public void onclick(view v) { 49         getfragmentmanager().popbackstack("startingfragment", 0); 50     } 51 }); 

i find interesting crash report listing crash being in oncreateview() method, yet line 48 declaration of onclick() method on button's onclicklistener.

i've looked following questions:

both of them seem indicate problem being related incorrect id when accessing xml fragment. don't think that's problem, however, xml portion fragment (and there's 1 layout fragment):

<linearlayout     android:layout_height="match_parent"     android:layout_width="match_parent"     android:orientation="vertical"      >      <button         android:id="@+id/restart_button"         android:layout_gravity="right"         android:layout_height="wrap_content"         android:layout_width="wrap_content"         android:paddingbottom="8dp"         android:paddingtop="8dp"         android:text="restart"          /> 

one thing might of concern: use same paradigm on many of fragments. app's function drill through series of questions achieve answer. "reset" button allows them go way beginning without going through of intermediate fragments they've seen along way. each of fragments has button on named r.id.reset_button. said, though, i've attempted replicate problem on end , cannot figure out how occurs.

i've read stuff indicates problem might related fragment somehow being detached activity, i've tried leaving app , returning, , still can't replicate bug.

i assume code works in many devices , bug not reproducible. recommendation have , own coding technique move posted code onviewcreated() method instead of oncreateview(). reason oncreateview not finish processing gui layout in time. @ least, easy try. luck in testing different devices.

sample code:

@override public view oncreateview(layoutinflater inflater, viewgroup container,                          bundle savedinstancestate) {     return inflater.inflate(r.layout.list_layout, container, false); }  @override public void onviewcreated(view view, bundle savedinstancestate) {    context thiscontext = view.getcontext();     mrestartbutton = (button) view.findviewbyid(r.id.restart_button);    mrestartbutton.settypeface(regulartf);    mrestartbutton.setonclicklistener(new view.onclicklistener() {    ... 

notes:

  • oncreateview() changed returning root view pass onto onviewcreated()
  • onviewcreated() doing ui work.

Comments

Popular posts from this blog

javascript - gulp-nodemon - nodejs restart after file change - Error: listen EADDRINUSE events.js:85 -

Fatal Python error: Py_Initialize: unable to load the file system codec. ImportError: No module named 'encodings' -

javascript - oscilloscope of speaker input stops rendering after a few seconds -