创建一个构建 RadioButton returns 一个 NullPointerException 的静态方法

Creating a static method that builds a RadioButton returns a NullPointerException

所以我有这个 static 方法来构建 RadioButton:

public static RadioButton createARadioButton()
{
    RadioButton radioButton = new RadioButton(null);
    return radioButton;
}

我有这个赋值语句:

radioButton = createARadioButton();

这给了我一个 NullPointerExeption。

现在我该如何编写静态方法来创建性能良好的 RadioButton? 我在这里做错了什么?

您不能为 RadioButton 传递空上下文参数。至少你需要这样的东西:

public static RadioButton createARadioButton(Context context)
{
    RadioButton radioButton = new RadioButton(context);
    return radioButton;
}