Java RadioGroup.setOnCheckedChangeListener不工作并返回null?

Java RadioGroup.setOnCheckedChangeListener不工作并返回null?,java,android,null,radio-group,jradiobutton,Java,Android,Null,Radio Group,Jradiobutton,我的名字是Amaya,我是java和Android Studio的新手。我正在为我的期末课程项目构建一个专家系统,但我被卡住了,因为我的单选按钮或放射组(老实说,我不知道哪些会出错)。实际上,我想做一件简单的事情,如果我检查一些单选按钮,我可以得到字符串,我可以在另一个布局中设置TextView。这是我的第一个布局: <ScrollView android:layout_width="match_parent" android:layout_heig

我的名字是Amaya,我是
java
Android Studio
的新手。我正在为我的期末课程项目构建一个专家系统,但我被卡住了,因为我的
单选按钮
放射组
(老实说,我不知道哪些会出错)。实际上,我想做一件简单的事情,如果我检查一些单选按钮,我可以得到字符串,我可以在另一个布局中设置
TextView
。这是我的第一个布局:

    <ScrollView
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:id="@+id/scrollView2" >
        <LinearLayout
            android:orientation="vertical"
            android:layout_width="match_parent"
            android:layout_height="match_parent">

            <TextView
                android:layout_marginTop="10dp"
                android:text="Isilah formulir pengecekan kesehatan dibawah ini sesuai dengan keadaan sapi anda!"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:id="@+id/textView3"
                android:layout_marginBottom="10dp"/>
            <View
                android:layout_width="match_parent"
                android:layout_height="2dp"
                android:background="#AFAFAF"
                android:layout_marginRight="13dp"
                android:layout_marginLeft="2dp"
                android:layout_marginBottom="5dp"
                />
            <TextView
                android:text="Nafsu makan:"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:id="@+id/x1" />

            <RadioGroup
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:orientation="vertical"
                android:id="@+id/a"
                android:onClick="onRGClick">

                <RadioButton
                    android:text="Normal"
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:id="@+id/a1" />

                <RadioButton
                    android:text="Tidak normal"
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:id="@+id/a2" />

            </RadioGroup>

            <TextView
                android:layout_marginTop="15dp"
                android:text="Cungur hidung:"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:id="@+id/textView4" />
            <RadioGroup
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:orientation="vertical"
                android:id="@+id/b"
                android:onClick="onRGClick">
                <RadioButton
                    android:text="Basah"
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:id="@+id/b1" />

                <RadioButton
                    android:text="Tidak basah"
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:id="@+id/b2" />
            </RadioGroup>
            <TextView
                android:layout_marginTop="15dp"
                android:text="Feses sapi:"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:id="@+id/textView3" />

            <RadioGroup
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:orientation="vertical"
                android:id="@+id/c"
                android:onClick="onRGClick">
                <RadioButton
                    android:text="Tidak ada"
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:id="@+id/c1" />

                <RadioButton
                    android:text="Normal"
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:id="@+id/c2" />

                <RadioButton
                    android:text="Lembek"
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:id="@+id/c3" />

                <RadioButton
                    android:text="Mencret"
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:id="@+id/c4" />

            </RadioGroup>
            <TextView
                android:layout_marginTop="15dp"
                android:text="Ada lendir dari hidung?"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:id="@+id/textView3" />

            <RadioGroup
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:orientation="vertical"
                android:id="@+id/d"
                android:onClick="onRGClick">
                <RadioButton
                    android:text="Ada"
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:id="@+id/d1" />

                <RadioButton
                    android:text="Tidak"
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:id="@+id/d2" />

            </RadioGroup>
            <TextView
                android:layout_marginTop="15dp"
                android:text="Frekuensi pernafasan:"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:id="@+id/textView3" />

            <RadioGroup
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:orientation="vertical"
                android:id="@+id/e"
                android:onClick="onRGClick">
                <RadioButton
                    android:text="Normal"
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:id="@+id/e1" />

                <RadioButton
                    android:text="Dipercepat"
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:id="@+id/e2" />

            </RadioGroup>
            <Button
                android:layout_marginTop="15dp"
                android:text="Proses"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:id="@+id/proses"
                android:layout_weight="1.00"
                android:layout_gravity="center"
                android:background="@color/colorBackground"
                android:textColor="#FFFFFF"
                android:textStyle="bold" />


        </LinearLayout>
    </ScrollView>
</LinearLayout>
错误消息是:

尝试调用虚拟方法“void” android.widget.RadioGroup.setOnCheckedChangeListener(android.widget.RadioGroup$OnCheckedChangeListener)' 关于空对象引用

当我添加
收音机[1]时出现程序错误。setOnCheckedChangeListener
bla bla bla bla。我希望你能帮助我。这是我的结果,如果需要的话

public class Informasi_Sehat extends Activity {
    public TextView tt0,tt1,tt2,tt3,tt4,tt5,tt6,tt7,tt8,tt9,tt10,tt11,tt12;
    public String t0,t1, t2, t3, t4, t5, t6, t7, t8, t9, t10, t11, t12;
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.informasi_sehat);
        iku();
        ((Button) findViewById(R.id.btn_kembalihome)).setOnClickListener(new View.OnClickListener() {
            public void onClick(View arg0) {
                finish();
            }
        });
    }

    public void iku(){
        tt0 = (TextView) findViewById(R.id.namaSpecies);
        tt1 = (TextView) findViewById(R.id.namaDeskripsi1);
        tt2 = (TextView) findViewById(R.id.namaDeskripsi2);
        tt3 = (TextView) findViewById(R.id.namaDeskripsi3);
        tt4 = (TextView) findViewById(R.id.namaDeskripsi4);
        tt5 = (TextView) findViewById(R.id.namaDeskripsi5);
        tt6 = (TextView) findViewById(R.id.namaDeskripsi6);
        tt7 = (TextView) findViewById(R.id.namaDeskripsi7);
        tt8 = (TextView) findViewById(R.id.namaDeskripsi8);
        tt9 = (TextView) findViewById(R.id.namaDeskripsi9);
        tt10 = (TextView) findViewById(R.id.namaDeskripsi10);
        tt11 = (TextView) findViewById(R.id.namaDeskripsi11);
        tt12 = (TextView) findViewById(R.id.namaDeskripsi12);
        tt0.setText(String.valueOf(t0));
        tt1.setText(String.valueOf(t1));
        tt2.setText(String.valueOf(t2));
        tt3.setText(String.valueOf(t3));
        tt4.setText(String.valueOf(t4));
        tt5.setText(String.valueOf(t5));
        tt6.setText(String.valueOf(t6));
        tt7.setText(String.valueOf(t7));
        tt8.setText(String.valueOf(t8));
        tt9.setText(String.valueOf(t9));
        tt10.setText(String.valueOf(t10));
        tt11.setText(String.valueOf(t11));
        tt12.setText(String.valueOf(t12));
    }



}

多谢各位。如果我的语法不好,我很抱歉。

您是在用Java开发专家系统吗?可能吗?

是的,我开发了我的java专家,并使用SQLite数据库来帮助它。我在这里的朋友也培养了他的java专家。但是,因为现在我尝试不使用数据库,只想用“if和elseif”以其他方式开发它(就像我上面的解释),所以我在Radio.Grups中得到了一个错误。你的意思是错误是因为我声明了错误类型的变量吗?就像真的一样,有可能不是字符串吗?
public class Informasi_Sehat extends Activity {
    public TextView tt0,tt1,tt2,tt3,tt4,tt5,tt6,tt7,tt8,tt9,tt10,tt11,tt12;
    public String t0,t1, t2, t3, t4, t5, t6, t7, t8, t9, t10, t11, t12;
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.informasi_sehat);
        iku();
        ((Button) findViewById(R.id.btn_kembalihome)).setOnClickListener(new View.OnClickListener() {
            public void onClick(View arg0) {
                finish();
            }
        });
    }

    public void iku(){
        tt0 = (TextView) findViewById(R.id.namaSpecies);
        tt1 = (TextView) findViewById(R.id.namaDeskripsi1);
        tt2 = (TextView) findViewById(R.id.namaDeskripsi2);
        tt3 = (TextView) findViewById(R.id.namaDeskripsi3);
        tt4 = (TextView) findViewById(R.id.namaDeskripsi4);
        tt5 = (TextView) findViewById(R.id.namaDeskripsi5);
        tt6 = (TextView) findViewById(R.id.namaDeskripsi6);
        tt7 = (TextView) findViewById(R.id.namaDeskripsi7);
        tt8 = (TextView) findViewById(R.id.namaDeskripsi8);
        tt9 = (TextView) findViewById(R.id.namaDeskripsi9);
        tt10 = (TextView) findViewById(R.id.namaDeskripsi10);
        tt11 = (TextView) findViewById(R.id.namaDeskripsi11);
        tt12 = (TextView) findViewById(R.id.namaDeskripsi12);
        tt0.setText(String.valueOf(t0));
        tt1.setText(String.valueOf(t1));
        tt2.setText(String.valueOf(t2));
        tt3.setText(String.valueOf(t3));
        tt4.setText(String.valueOf(t4));
        tt5.setText(String.valueOf(t5));
        tt6.setText(String.valueOf(t6));
        tt7.setText(String.valueOf(t7));
        tt8.setText(String.valueOf(t8));
        tt9.setText(String.valueOf(t9));
        tt10.setText(String.valueOf(t10));
        tt11.setText(String.valueOf(t11));
        tt12.setText(String.valueOf(t12));
    }



}