android findViewById返回空值

android findViewById返回空值,android,null,android-linearlayout,findviewbyid,Android,Null,Android Linearlayout,Findviewbyid,我在寻找线性布局时遇到问题。。。 这是xml布局: <?xml version="1.0" encoding="utf-8"?> <ScrollView xmlns:android="http://schemas.android.com/apk/res/android" xmlns:binding="http://www.gueei.com/android-binding/" xmlns:tools="http://schemas.android.com/too

我在寻找线性布局时遇到问题。。。 这是xml布局:

<?xml version="1.0" encoding="utf-8"?>
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:binding="http://www.gueei.com/android-binding/"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:fillViewport="true"
    tools:context=".controllers.ElencoInfrazioni" >

<LinearLayout
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:orientation="vertical"
    android:padding="15dp" >

    <LinearLayout
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:orientation="horizontal" >

        <TextView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_gravity="center_vertical"
            android:text="Infrazione: " />

        <Spinner
            android:id="@+id/elencoInfrazioni"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:layout_weight="1" />
    </LinearLayout>

    <TableLayout
        android:id="@+id/tabellaDatiElencoInfrazioni"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:layout_marginTop="10dp"
        android:stretchColumns="*"
        android:visibility="gone" > 

        <TableRow>
            <TextView
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="Art. 3: " />

            <TextView
                android:id="@+id/articolo3ElencoInfrazioni"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="non specificato"
                android:textStyle="bold" />

            <LinearLayout
                android:id="@+id/panelArticolo4ElencoInfrazioni"
                android:layout_width="fill_parent"
                android:layout_height="wrap_content"
                android:orientation="horizontal" >

                <TextView
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:text="Art. 4: " />

                <TextView
                    android:id="@+id/articolo4ElencoInfrazioni"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:text="non specificato"
                    android:textStyle="bold" />
            </LinearLayout>
        </TableRow>
        ....
每个findViewById都正常,但LinearLayout Panel Articolo4给我空值…我需要线性布局来设置其可见性…我做错了什么


提前感谢

不要在任何地方使用“this”一词,在您的init方法中,“this”指的是init,而不是您的活动。

您确定所有其他视图都可以吗?在您尝试使用它们之前,它们不会在初始化时给出任何错误。可能是您的视图未在onCreate初始化?如果您使用的是片段,您可以尝试在onCreateView而不是onCreate上初始化视图。

这与清理项目和重建没有区别。如果表中有多行,则代码似乎是正确的。。。不同行的线性布局是否使用相同的id?
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
            this.setContentView(R.layout.elenco_infrazioni);
    init();
}
private void init() {
    tabellaDati = (TableLayout) this
            .findViewById(R.id.tabellaDatiElencoInfrazioni);
    elencoInfrazioni = (Spinner) this.findViewById(R.id.elencoInfrazioni);
    panelArticolo4 = (LinearLayout) this. 
            findViewById(R.id.panelArticolo4ElencoInfrazioni);
    articolo3 = (TextView) this
            .findViewById(R.id.articolo3ElencoInfrazioni);
    articolo4 = (TextView) this
            .findViewById(R.id.articolo4ElencoInfrazioni);
}