java - Can access TextView but not LinearLayout declared in the same way -
i want add together textview linearlayout in java, access linearlayout linlay_container
in make_systematics()
, nullpointerexception. have exact same code defining linearlayout , textview textview_systematics
within of linearlayout. can access textview, not linearlayout. wrong here?
this layout fragment , included <fragment>
-tag, in case important.
the xml file (fragment_species_systematics.xml):
<?xml version="1.0" encoding="utf-8"?> <linearlayout xmlns:android="http://schemas.android.com/apk/res/android" android:id = "@+id/linlay_fragment_species_systematics" android:layout_width = "match_parent" android:layout_height = "wrap_content" android:orientation = "vertical" > <textview android:id = "@+id/textview_fragment_species_systematics" android:layout_width = "match_parent" android:layout_height = "wrap_content" /> </linearlayout>
the java file:
public class fragment_species_systematics extends fragment { linearlayout linlay_container; textview textview_systematics; view view; public fragment_species_systematics() {} @override public view oncreateview(layoutinflater inflater, viewgroup container, bundle savedinstancestate) { view = inflater.inflate(r.layout.fragment_species_systematics, container, false); homecoming view; } @override public void onactivitycreated(bundle savedinstancestate) { super.onactivitycreated(savedinstancestate); linlay_container = (linearlayout) getactivity().findviewbyid(r.id.linlay_fragment_species_systematics); textview_systematics = (textview) getactivity().findviewbyid(r.id.textview_fragment_species_systematics); } public void make_systematics(string json_systematics) { if (textview_systematics.isattachedtowindow()) {log.i("debug", "tv attached");} else {log.i("debug", "tv not attached");} if (linlay_container.isattachedtowindow()) {log.i("debug", "ll attached");} else {log.i("debug", "ll not attached");} } }
figured out, unfortunately without finding reason why have following: apparently 1 can not access "global" linearlayout. have include linearlayout , access that one, works.
my working xml file:
<?xml version="1.0" encoding="utf-8"?> <linearlayout xmlns:android="http://schemas.android.com/apk/res/android" > <linearlayout android:id = "@+id/linlay_fragment_species_systematics" android:layout_width = "match_parent" android:layout_height = "wrap_content" android:orientation = "vertical" > <textview android:id = "@+id/textview_fragment_species_systematics" android:layout_width = "match_parent" android:layout_height = "wrap_content" /> </linearlayout> </linearlayout>
java android-fragments nullpointerexception android-linearlayout
No comments:
Post a Comment