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
Post a Comment