0

我遇到了一些问题,我的 XML 中有两组单选按钮,它们处理了一个活动。它只是在第 48 行出现空点异常崩溃: int langungeId = languageGroup.getCheckedRadioButtonId();

我已将 XML 中的“默认”选中按钮设置为按钮组中的按钮之一,那么为什么它没有获得有效值?:(

public class FirstTimeSelectMenu extends Activity{

private RadioGroup languageGroup;
private RadioGroup storageGroup;
private Button okButton;
private String getStorage;



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

    languageGroup = (RadioGroup)this.findViewById(R.id.languageGroup);
    storageGroup = (RadioGroup)this.findViewById(R.id.storageGroup);
    okButton = (Button)findViewById(R.id.okBtn);



    okButton.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {




            int languangeId = languageGroup.getCheckedRadioButtonId();
            int storageId = storageGroup.getCheckedRadioButtonId();
            RadioButton languageb = (RadioButton)findViewById(languangeId);
            RadioButton storageb = (RadioButton)findViewById(storageId);

            if(languageb.equals("Norwegian")){
                    //Need to fix this!
            }
            if(languageb.equals("English")){
                    //Need to fix this!
            }
            if(storageb.equals("SD Card")){
               String sdStoragePath = Environment.getExternalStorageDirectory().toString() + "/PictureTalk/";
               FileInteraction fi = new FileInteraction();
               fi.firstTimeFillPath(getResources(), "PictureTalk/Food", sdStoragePath +"PictureTalk/Food");
               fi.firstTimeFillPath(getResources(), "PrivatePictures", Environment.getExternalStorageDirectory().toString() +"PrivatePictures");
               Intent intent = new Intent(getApplicationContext(),MainMenuActivity.class);
               intent.putExtra("dataStorePath",sdStoragePath);
               startActivity(intent);
            }
        }
    });
}}

我的 XML 文件

    <?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="horizontal"
android:layout_width="fill_parent"
android:layout_height="fill_parent">

<TextView
    android:id="@+id/languagetext"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_alignParentTop="true"
    android:layout_centerHorizontal="true"
    android:layout_marginTop="236dp"
    android:text="Choose language" />

<RadioGroup
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_alignEnd="@+id/languagetext"
    android:layout_alignRight="@+id/languagetext"
    android:layout_below="@+id/languageGroup">



    <RadioButton
        android:id="@+id/norwegianRadioBtn"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:checked="true"
        android:text="Norwegian" />

    <RadioButton
        android:id="@+id/englishRadioBtn"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="English" />

</RadioGroup>


<TextView
    android:id="@+id/internal_sd"
    android:layout_width="464dp"
    android:layout_height="wrap_content"
    android:layout_alignParentTop="true"
    android:layout_centerHorizontal="true"
    android:layout_marginTop="236dp"
    android:text="Do you want to store the data to:" />

<RadioGroup
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_alignParentLeft="true"
    android:layout_alignParentStart="true"
    android:layout_alignParentTop="true"
    android:id="@+id/storageGroup">



    <RadioButton
        android:id="@+id/sdcardRadioBtn"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_gravity="center_horizontal"
        android:checked="true"
        android:text="SD card" />


    <RadioButton
        android:id="@+id/internalRadioBtn"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_gravity="right"
        android:text="Internal storage" />
</RadioGroup>

<Button
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:text="Ok"
    android:id="@+id/okBtn"
    android:layout_gravity="bottom" />

4

1 回答 1

0

首先,为哪个元素分配了 id "@+id/languageGroup",因为它似乎没有在您的 XML 中声明

于 2014-11-20T00:49:01.747 回答