java - Setting view in constructor Android with fragment -


i'm getting java java.lang.nullpointerexception error when i'm trying set view in class while using constructor. can't see i'm doing wrong here.. here's code:

public class homefragment extends fragment {   public homefragment() {      // required empty public constructor  }   @override  public view oncreateview(layoutinflater inflater, viewgroup container,                           bundle savedinstancestate) {       view rootview = inflater.inflate(r.layout.fragment_home, container, false);       // define webview stuff      dataselector dataselector = new dataselector(rootview);      dataselector.getdata(); 

-

public class dataselector {     public view mrootview;      public dataselector(view rootview){         mrootview = rootview;     }      textview resultview = (textview) mrootview.findviewbyid(r.id.result);      public void getdata(){        ... 

the initialization code attributes run before constructor. mrootview empty when resultview initialized.


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 -