java - Can access TextView but not LinearLayout declared in the same way -
I want to add TextView to a LinearLayout in Java, but as soon as I use LinearLayout linlay_container
in < Code> make_systematics () , I get a NullPointerException. I have the exact code to define inside the LinearLayout and a text view textview_systematics
I can access the text view , but the linear layout not < / P>
This layout is a piece and contains & lt; Fragment & gt;
-Tags are included, just this can be important.
XML file (fragment_species_systematics.xml):
& lt ;? Xml version = "1.0" encoding = "UTF-8"? & Gt; & Lt; 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" & gt; & Lt; TextView Android: id = "@ + id / textView_fragment_species_systematics" Android: layout_width = "match_parent" Android: layout_height = "wrap_content" /> & Lt; / LinearLayout & gt;
Java file:
Expands public class fragment cypscisestatics fragment {LinearLayout linlay_container; TextViewtextSystemmatics; View View; Public Fragment_Species_Systematics () {} @ Override Public View Creatives (LayoutsInflator Inflator, View Group Container, Bundle Saved InstantState) {view = inflater.inflate (R. Fragment_spacees_symptactics, containers, falls); Return view; } @ Override Public Empty on Activity Crateed (Bundle Saved Instantstate) {Super. On-activity creativity (saved instenstate); Linlay_container = (LinearLayout) getActivity (). FindViewById (R.id.linlay_fragment_species_systematics); Textview_systematics = (TextView) getActivity () FindViewById (R.id.textView_fragment_species_systematics); } Public Zero make_systematics (string json_systematics) {if (textview_systematics.isAttachedToWindow ()) {Log.i ("DEBUG", "TV is attached"); else {Log.i ("DEBUG", "TV is not attached" );} If (linlay_container.isAttachedToWindow ()) {Log.i ("DEBUG", "has been attached");} other {Log.i ("DEBUG", "not attached");}}} <
Unfortunately, understand it without any reason, why . Do the following: Apparently no one can reach the "global" linear line. The XML file of my work:
& lt ;? Xml version = "1.0" encoding = "UTF-8"? & Gt; & Lt; LinearLayout xmlns: android = "http://schemas.android.com/apk/res/android" & gt; & Lt; LinearLayout Android: id = "@ + id / linlay_fragment_species_systematics" Android: layout_width = "match_parent" Android: layout_height = "wrap_content" android: orientation = "vertical" & gt; & Lt; TextView Android: id = "@ + id / textView_fragment_species_systematics" Android: layout_width = "match_parent" Android: layout_height = "wrap_content" /> & Lt; / LinearLayout & gt; & Lt; / LinearLayout & gt;
Comments
Post a Comment