Java 尝试调用虚拟方法';void android.widget.RadioButton.setTypeface(android.graphics.Typeface)和#x27;关于空对象引用

Java 尝试调用虚拟方法';void android.widget.RadioButton.setTypeface(android.graphics.Typeface)和#x27;关于空对象引用,java,android,nullpointerexception,Java,Android,Nullpointerexception,我是执行无线电组。当我尝试运行该应用程序时,会出现以下错误java.lang.NullPointerException:尝试在空对象引用上调用虚拟方法“void android.widget.RadioGroup.setOnCheckedChangeListener(android.widget.RadioGroup$OnCheckedChangeListener)” radio_group_your_choice = (RadioGroup) findViewById(R.id.radio_g

我是执行无线电组。当我尝试运行该应用程序时,会出现以下错误java.lang.NullPointerException:尝试在空对象引用上调用虚拟方法“void android.widget.RadioGroup.setOnCheckedChangeListener(android.widget.RadioGroup$OnCheckedChangeListener)”

radio_group_your_choice = (RadioGroup) findViewById(R.id.radio_group_your_choice);
        male_radioButton = (RadioButton) findViewById(R.id.male_radioButton);
        female_radioButton = (RadioButton) findViewById(R.id.female_radioButton);

        radio_group_your_choice.setOnCheckedChangeListener(new RadioGroup.OnCheckedChangeListener() {
            @Override
            public void onCheckedChanged(RadioGroup group, int checkedId)
            {
                RadioButton radioButton = (RadioButton) findViewById(checkedId);
                gender = radioButton.getText().toString();
            }
        });

<RelativeLayout
                android:layout_width="fill_parent"
                android:layout_height="wrap_content"
                android:layout_marginTop="0dp"
                android:layout_marginBottom="15dp">

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

                    <RadioButton
                        android:id="@+id/delivery_radioButton"
                        android:layout_width="wrap_content"
                        android:layout_height="wrap_content"
                        android:text="Pick Up"
                        android:textColor="@color/dark_grey"/>

                    <RadioButton
                        android:id="@+id/pickup_radioButton"
                        android:layout_width="wrap_content"
                        android:layout_height="wrap_content"
                        android:layout_marginLeft="20dp"
                        android:layout_marginStart="20dp"
                        android:text="Delivery"
                        android:textColor="@color/dark_grey"/>


                </RadioGroup>

            </RelativeLayout>
radio\u group\u your\u choice=(RadioGroup)findViewById(R.id.radio\u group\u your\u choice);
male_radioButton=(radioButton)findViewById(R.id.male_radioButton);
雌性按钮=(radioButton)findViewById(R.id.female按钮);
radio\u group\u您的选择。setOnCheckedChangeListener(新的RadioGroup.OnCheckedChangeListener(){
@凌驾
检查更改后的公共无效(RadioGroup组,int checkedId)
{
RadioButton RadioButton=(RadioButton)findViewById(checkedId);
性别=radioButton.getText().toString();
}
});

此无线电组为空:

radio_group_your_choice
setOnCheckedChangeListener

if (radio_group_your_choice!= null)

为了避免此验证。

仍然存在相同的错误java.lang.NullPointerException:尝试在空对象referenceradioGroup上调用虚拟方法“void android.widget.RadioGroup.setOnCheckedChangeListener(android.widget.RadioGroup$OnCheckedChangeListener)”,radioButtons为空。尝试检查为什么为空,屏幕上是否有它,或者它在另一个布局中?这个单选按钮似乎没有创建Yes,但是你是在创建这个布局还是另一个布局时加载的?这个布局如何调用?你在setContentView中放了什么?在这里我添加了代码。我已经设置了活动搜索