我在使用AppCompatRadioButton
时遇到了一些问题在xml预览中出现:
The following classes could not be instantiated:
- android.support.v7.widget.AppCompatRadioButton (Open Class, Show Exception, Clear Cache)
Tip: Use View.isInEditMode() in your custom views to skip code or show sample data when shown in the IDE Exception Details android.content.res.Resources$NotFoundException: Unable to find resource ID #0x1ff0034 at android.content.res.Resources.getResourceName(Resources.java:2235) at android.content.res.Resources.loadDrawableForCookie(Resources.java:2602) at android.content.res.Resources.loadDrawable(Resources.java:2540) at android.content.res.Resources.getDrawable(Resources.java:806) at android.content.Context.getDrawable(Context.java:458) at android.support.v4.content.ContextCompatApi21.getDrawable(ContextCompatApi21.java:26) at android.support.v4.content.ContextCompat.getDrawable(ContextCompat.java:321) at android.support.v7.widget.AppCompatDrawableManager.getDrawable(AppCompatDrawableManager.java:180) at android.support.v7.widget.AppCompatDrawableManager.getDrawable(AppCompatDrawableManager.java:173) at android.support.v7.widget.AppCompatCompoundButtonHelper.loadFromAttributes(AppCompatCompoundButtonHelper.java:63) at android.support.v7.widget.AppCompatRadioButton.<init>(AppCompatRadioButton.java:61) at android.support.v7.widget.AppCompatRadioButton.<init>(AppCompatRadioButton.java:54) at java.lang.reflect.Constructor.newInstance(Constructor.java:423) at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:704) at android.view.LayoutInflater.rInflate_Original(LayoutInflater.java:835) at android.view.LayoutInflater_Delegate.rInflate(LayoutInflater_Delegate.java:70) at android.view.LayoutInflater.rInflate(LayoutInflater.java:811) at android.view.LayoutInflater.rInflateChildren(LayoutInflater.java:798) at android.view.LayoutInflater.rInflate_Original(LayoutInflater.java:838) at android.view.LayoutInflater_Delegate.rInflate(LayoutInflater_Delegate.java:70) at android.view.LayoutInflater.rInflate(LayoutInflater.java:811) at android.view.LayoutInflater.rInflateChildren(LayoutInflater.java:798) at android.view.LayoutInflater.rInflate_Original(LayoutInflater.java:838) at android.view.LayoutInflater_Delegate.rInflate(LayoutInflater_Delegate.java:70) at android.view.LayoutInflater.rInflate(LayoutInflater.java:811) at android.view.LayoutInflater.rInflateChildren(LayoutInflater.java:798) at android.view.LayoutInflater.rInflate_Original(LayoutInflater.java:838) at android.view.LayoutInflater_Delegate.rInflate(LayoutInflater_Delegate.java:70) at android.view.LayoutInflater.rInflate(LayoutInflater.java:811) at android.view.LayoutInflater.rInflateChildren(LayoutInflater.java:798) at android.view.LayoutInflater.rInflate_Original(LayoutInflater.java:838) at android.view.LayoutInflater_Delegate.rInflate(LayoutInflater_Delegate.java:70) at android.view.LayoutInflater.rInflate(LayoutInflater.java:811) at android.view.LayoutInflater.rInflateChildren(LayoutInflater.java:798) at android.view.LayoutInflater.rInflate_Original(LayoutInflater.java:838) at android.view.LayoutInflater_Delegate.rInflate(LayoutInflater_Delegate.java:70) at android.view.LayoutInflater.rInflate(LayoutInflater.java:811) at android.view.LayoutInflater.rInflateChildren(LayoutInflater.java:798) at android.view.LayoutInflater.inflate(LayoutInflater.java:515) at android.view.LayoutInflater.inflate(LayoutInflater.java:394)
Xml:`
<android.support.v7.widget.AppCompatRadioButton
android:id="@+id/rb_g"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:onClick="onRadioButtonClicked"/>
<android.support.v7.widget.AppCompatRadioButton
android:id="@+id/rb_mg"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:onClick="onRadioButtonClicked"/>
</RadioGroup>`
我的代码中有另一个RadioButton,它工作正常。我只有这两个问题
答案 0 :(得分:0)
如果您使用androidx,则应在xml中使用
androidx.appcompat.widget.AppCompatRadioButton
<androidx.appcompat.widget.AppCompatRadioButton
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="@string/external_resource"
android:fontFamily="@font/amaranth_italic"
android:textColor="@color/colorSecondary"
android:textSize="17sp"/>
但查看错误时会出现资源错误
答案 1 :(得分:0)
尝试一下。
<RadioButton
android:id="@+id/rb_mg"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:onClick="onRadioButtonClicked"/>