android.content.res.ResourcesRadioGroup 中的 $NotFoundException
android.content.res.Resources$NotFoundException in RadioGroup
我想与 RadioGroup
建立对话。当我尝试打开对话框时,我的应用程序崩溃了,而且我没有看到警告对话框。这就是我使用 RadioGroup
创建对话框的方式:
private void showRadioButtonDialog() {
final Dialog dialog = new Dialog(GenerateRaportActivity.this);
dialog.requestWindowFeature(Window.FEATURE_NO_TITLE);
dialog.setContentView(R.layout.radiobutton_dialog);
List<String> stringList = new ArrayList<>();
for (int i = 0; i < 5; i++) {
stringList.add("RadioButton " + (i + 1));
}
RadioGroup rg = (RadioGroup) dialog.findViewById(R.id.radio_group);
for (int i = 0; i < stringList.size(); i++) {
RadioButton rb = new RadioButton(GenerateRaportActivity.this);
rb.setText(stringList.get(i));
rg.addView(rb);
}
dialog.show();
}
当我尝试显示这个对话框时,我看到了这个:
FATAL EXCEPTION: main
Process: com.maps, PID: 901
android.content.res.Resources$NotFoundException: File res/drawable/abc_btn_radio_material.xml from drawable resource ID #0x7f020018
at android.content.res.Resources.loadDrawable(Resources.java:3443)
at android.content.res.TypedArray.getDrawable(TypedArray.java:602)
at android.widget.CompoundButton.<init>(CompoundButton.java:78)
at android.widget.RadioButton.<init>(RadioButton.java:63)
at android.widget.RadioButton.<init>(RadioButton.java:59)
at android.widget.RadioButton.<init>(RadioButton.java:55)
at com.smok.maps.Activity.GenerateRaportActivity.showRadioButtonDialog(GenerateRaportActivity.java:162)
at com.smok.maps.Activity.GenerateRaportActivity.access[=12=]0(GenerateRaportActivity.java:31)
at com.smok.maps.Activity.GenerateRaportActivity.onClick(GenerateRaportActivity.java:86)
at android.view.View.performClick(View.java:4640)
at android.view.View$PerformClick.run(View.java:19425)
at android.os.Handler.handleCallback(Handler.java:733)
at android.os.Handler.dispatchMessage(Handler.java:95)
at android.os.Looper.loop(Looper.java:146)
at android.app.ActivityThread.main(ActivityThread.java:5593)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:515)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1283)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1099)
at dalvik.system.NativeStart.main(Native Method)
布局文件:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<RadioGroup
android:id="@+id/radio_group"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_gravity="center_vertical"
android:orientation="vertical">
</RadioGroup>
</LinearLayout>
尝试使用这个作为实例:
RadioGroup dynamicRadiogroup = new RadioGroup(MainActivity.this);
RadioButton radiobutton1 = new RadioButton(MainActivity.this);
RadioButton radiobutton2 = new RadioButton(MainActivity.this);
RadioButton radiobutton3 = new RadioButton(MainActivity.this);
RelativeLayout relativelayout =
(RelativeLayout)findViewById(R.id.relativelayout1);
radiobutton1.setText("Android");
radiobutton2.setText("PHP");
radiobutton3.setText("WordPress");
dynamicRadiogroup.addView(radiobutton1);
dynamicRadiogroup.addView(radiobutton2);
dynamicRadiogroup.addView(radiobutton3);
RelativeLayout.LayoutParams layoutparams = new RelativeLayout.LayoutParams
(LayoutParams.WRAP_CONTENT,LayoutParams.WRAP_CONTENT);
dynamicRadiogroup.setLayoutParams(layoutparams);
relativelayout.addView(dynamicRadiogroup);
我想与 RadioGroup
建立对话。当我尝试打开对话框时,我的应用程序崩溃了,而且我没有看到警告对话框。这就是我使用 RadioGroup
创建对话框的方式:
private void showRadioButtonDialog() {
final Dialog dialog = new Dialog(GenerateRaportActivity.this);
dialog.requestWindowFeature(Window.FEATURE_NO_TITLE);
dialog.setContentView(R.layout.radiobutton_dialog);
List<String> stringList = new ArrayList<>();
for (int i = 0; i < 5; i++) {
stringList.add("RadioButton " + (i + 1));
}
RadioGroup rg = (RadioGroup) dialog.findViewById(R.id.radio_group);
for (int i = 0; i < stringList.size(); i++) {
RadioButton rb = new RadioButton(GenerateRaportActivity.this);
rb.setText(stringList.get(i));
rg.addView(rb);
}
dialog.show();
}
当我尝试显示这个对话框时,我看到了这个:
FATAL EXCEPTION: main
Process: com.maps, PID: 901
android.content.res.Resources$NotFoundException: File res/drawable/abc_btn_radio_material.xml from drawable resource ID #0x7f020018
at android.content.res.Resources.loadDrawable(Resources.java:3443)
at android.content.res.TypedArray.getDrawable(TypedArray.java:602)
at android.widget.CompoundButton.<init>(CompoundButton.java:78)
at android.widget.RadioButton.<init>(RadioButton.java:63)
at android.widget.RadioButton.<init>(RadioButton.java:59)
at android.widget.RadioButton.<init>(RadioButton.java:55)
at com.smok.maps.Activity.GenerateRaportActivity.showRadioButtonDialog(GenerateRaportActivity.java:162)
at com.smok.maps.Activity.GenerateRaportActivity.access[=12=]0(GenerateRaportActivity.java:31)
at com.smok.maps.Activity.GenerateRaportActivity.onClick(GenerateRaportActivity.java:86)
at android.view.View.performClick(View.java:4640)
at android.view.View$PerformClick.run(View.java:19425)
at android.os.Handler.handleCallback(Handler.java:733)
at android.os.Handler.dispatchMessage(Handler.java:95)
at android.os.Looper.loop(Looper.java:146)
at android.app.ActivityThread.main(ActivityThread.java:5593)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:515)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1283)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1099)
at dalvik.system.NativeStart.main(Native Method)
布局文件:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<RadioGroup
android:id="@+id/radio_group"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_gravity="center_vertical"
android:orientation="vertical">
</RadioGroup>
</LinearLayout>
尝试使用这个作为实例:
RadioGroup dynamicRadiogroup = new RadioGroup(MainActivity.this);
RadioButton radiobutton1 = new RadioButton(MainActivity.this);
RadioButton radiobutton2 = new RadioButton(MainActivity.this);
RadioButton radiobutton3 = new RadioButton(MainActivity.this);
RelativeLayout relativelayout =
(RelativeLayout)findViewById(R.id.relativelayout1);
radiobutton1.setText("Android");
radiobutton2.setText("PHP");
radiobutton3.setText("WordPress");
dynamicRadiogroup.addView(radiobutton1);
dynamicRadiogroup.addView(radiobutton2);
dynamicRadiogroup.addView(radiobutton3);
RelativeLayout.LayoutParams layoutparams = new RelativeLayout.LayoutParams
(LayoutParams.WRAP_CONTENT,LayoutParams.WRAP_CONTENT);
dynamicRadiogroup.setLayoutParams(layoutparams);
relativelayout.addView(dynamicRadiogroup);