无法找到视图并获得空引用

Unable to find the view and getting a null reference

您好,我正在通过 Udacity 课程学习 android 开发,我在尝试向 LinearLayout 添加子视图时遇到错误。
以下是 xml 文件和 activity 的 class 文件
请帮忙
我得到的错误是

原因:java.lang.NullPointerException:尝试在空对象引用

上调用虚拟方法'void android.widget.LinearLayout.addView(android.view.View)'

numbers_activity.xml

    <?xml version="1.0" encoding="utf-8"?>
    <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
            xmlns:app="http://schemas.android.com/apk/res-auto"
            xmlns:tools="http://schemas.android.com/tools"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:orientation="vertical"
            android:id="@+id/rootView"
            tools:context="com.example.android.miwok.NumbersActivity">


    </LinearLayout>

NumversActivity.java

    package com.example.android.miwok;

    import android.support.v7.app.AppCompatActivity;
    import android.os.Bundle;
    import android.util.Log;
    import android.widget.LinearLayout;
    import android.widget.TextView;

    import java.util.ArrayList;

    public class NumbersActivity extends AppCompatActivity {

            @Override
            protected void onCreate(Bundle savedInstanceState) {
                    super.onCreate(savedInstanceState);
                    setContentView(R.layout.activity_phrases);

                    ArrayList<String> words = new ArrayList<String>();
                    words.add("one");
                    words.add("two");
                    words.add("three");
                    words.add("four");
                    words.add("five");
                    words.add("six");
                    words.add("seven");
                    words.add("eight");
                    words.add("nine");
                    words.add("ten");

                    LinearLayout rootView = (LinearLayout) findViewById(R.id.rootView);

                    TextView wordView = new TextView(this);
                    wordView.setText(words.get(1));
                    rootView.addView(wordView);

            }
    }

您必须将正确的布局设置为 Activity

将 onCreate 方法中的第二行更改为:

setContentView(numbers_activity.xml);

您的布局文件是 numbers_activity.xml。但是您将 activity_phrases 设置为 Activity