Android Activity文件调用setText

问题遇到的现象和发生背景

Android Studio 中Activity文件调用setText出错

用代码块功能插入代码,请勿粘贴截图

这是Activity文件

public class MainActivity extends AppCompatActivity {
    private RadioGroup radioGroup;
    private View textView;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        radioGroup=findViewById(R.id.rg);
        textView=findViewById(R.id.tv);
        radioGroup.setOnCheckedChangeListener(new RadioGroup.OnCheckedChangeListener() {
            @Override
            public void onCheckedChanged(RadioGroup radioGroup, int i) {
                if(i==R.id.nan){
                    textView.setText("您是男的");
                }else{
                    textView.setText("您是女的");
                }
            }
        });

    }
}

这是它的布局


<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:padding="8dp"
    tools:context=".MainActivity">
    <RadioGroup
        android:id="@+id/rg"
        android:layout_width="match_parent"
        android:layout_height="match_parent">
    <RadioButton
        android:id="@+id/nan"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:text="男"/>
    <RadioButton
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:text="女"/>
    RadioGroup>

    <TextView
        android:id="@+id/tv"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:textSize="30dp"/>
运行结果及报错内容

img

我想要达到的结果

哪里错了,运行成功

你这TextView咋还是自定义的呢?

img

import android.widget.TextView;


定义的地方改成这样试试

private TextView textView;

这样试试

textView=(TextView)findViewById(R.id.tv);

img