当前位置: 首页 > 知识库问答 >
问题:

尽管以前工作过,但“inflating类按钮时出错”

阳凌
2023-03-14

在我的布局中实现了一些按钮后,在应用程序部署期间logcat中会出现以下错误:

<?xml version="1.0" encoding="utf-8"?>
<ScrollView
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:layout_width="match_parent"
    android:layout_height="wrap_content">

    <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:paddingBottom="@dimen/activity_vertical_margin"
        android:paddingLeft="@dimen/activity_horizontal_margin"
        android:paddingRight="@dimen/activity_horizontal_margin"
        android:paddingTop="@dimen/activity_vertical_margin">

        <TextView
            android:id="@+id/Information_textView"
            style="@android:style/TextAppearance.Large"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="@string/information"
            android:textColor="@android:color/black" />
        <TableLayout
            android:id="@+id/Information_tableLayout"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_centerHorizontal="true"
            android:layout_marginBottom="20dp"
            android:layout_below="@id/Information_textView">

            <TableRow
                android:id="@+id/tableRow0"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content">

                <Button
                    android:id="@+id/Information_btnMale"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:drawableStart="@drawable/ic_male"
                    android:text="@string/male"
                    android:textColor="@android:color/white"
                    android:textSize="30sp"/>
            </TableRow>

            <TableRow
                android:id="@+id/tableRow1"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content">

                <Button
                    android:id="@+id/Information_btnFemale"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:drawableStart="@drawable/female"
                    android:text="@string/female"
                    android:textColor="@android:color/white"
                    android:textSize="30sp"/>
            </TableRow>
        </TableLayout>
    </RelativeLayout>
</ScrollView>
public class FragmentInformation extends android.support.v4.app.Fragment {

    public FragmentInformation() {
    }

    @Override
    public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {

        return inflater.inflate(R.layout.information, container, false);
    }

    @Override
    public void onActivityCreated(@Nullable Bundle savedInstanceState) {
        View v = getView();
        assert v != null;


        button0 = (Button) v.findViewById(R.id.Information_btnMale);
        button0.setOnClickListener(new View.OnClickListener()
        {
            @Override
            public void onClick(View v)
            {
                HeaderDialog headerDialog = new HeaderDialog(getActivity());
                headerDialog.setTitle(getResources().getString(R.string.male);                headerDialog.setMessage(getResources().getString(R.string.male_information);
                headerDialog.setNegativeButton("OK", null);
            }
        });


        Button button1 = (Button) v.findViewById(R.id.Information_btnFemale);
        button1.setOnClickListener(new View.OnClickListener()
        {
            @Override
            public void onClick(View v)
            {
                HeaderDialog headerDialog = new HeaderDialog(getActivity());
                headerDialog.setTitle(getResources().getString(R.string.female);
                headerDialog.setNegativeButton("OK", null);
            }
        });


        super.onActivityCreated(savedInstanceState);
    }
}

洛克卡特

06-27 18:44:58.214 7756-7756/com.companyname.informationapp E/AndroidRuntime: FATAL EXCEPTION: main
                                                                                    Process: com.companyname.informationapp, PID: 7756
                                                                                    android.view.InflateException: Binary XML file line #413: Error inflating class Button
                                                                                        at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:713)
                                                                                        at android.view.LayoutInflater.rInflate(LayoutInflater.java:755)
                                                                                        at android.view.LayoutInflater.rInflate(LayoutInflater.java:758)
                                                                                        at android.view.LayoutInflater.rInflate(LayoutInflater.java:758)
                                                                                        at android.view.LayoutInflater.rInflate(LayoutInflater.java:758)
                                                                                        at android.view.LayoutInflater.inflate(LayoutInflater.java:492)
                                                                                        at android.view.LayoutInflater.inflate(LayoutInflater.java:397)
                                                                                        at com.companyname.informationapp.FragmentInformation.onCreateView(FragmentInformation.java:30)
                                                                                        at android.support.v4.app.Fragment.performCreateView(Fragment.java:2192)
                                                                                        at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:1299)
                                                                                        at android.support.v4.app.FragmentManagerImpl.moveFragmentToExpectedState(FragmentManager.java:1528)
                                                                                        at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:1595)
                                                                                        at android.support.v4.app.BackStackRecord.executeOps(BackStackRecord.java:758)
                                                                                        at android.support.v4.app.FragmentManagerImpl.executeOps(FragmentManager.java:2363)
                                                                                        at android.support.v4.app.FragmentManagerImpl.executeOpsTogether(FragmentManager.java:2149)
                                                                                        at android.support.v4.app.FragmentManagerImpl.optimizeAndExecuteOps(FragmentManager.java:2103)
                                                                                        at android.support.v4.app.FragmentManagerImpl.execSingleAction(FragmentManager.java:1984)
                                                                                        at android.support.v4.app.BackStackRecord.commitNowAllowingStateLoss(BackStackRecord.java:626)
                                                                                        at android.support.v4.app.FragmentStatePagerAdapter.finishUpdate(FragmentStatePagerAdapter.java:166)
                                                                                        at android.support.v4.view.ViewPager.populate(ViewPager.java:1268)
                                                                                        at android.support.v4.view.ViewPager.setCurrentItemInternal(ViewPager.java:668)
                                                                                        at android.support.v4.view.ViewPager.setCurrentItemInternal(ViewPager.java:630)
                                                                                        at android.support.v4.view.ViewPager.setCurrentItem(ViewPager.java:611)

共有1个答案

毛淳
2023-03-14

也许,您可能已经从支持库23.2.0升级,之后进行了更改

由于内存使用和配置更新问题,它在23.3.0中被删除。在23.4.0中,添加了相同的功能,但需要手动启用

static {
    AppCompatDelegate.setCompatVectorFromSourcesEnabled(true);
}
 类似资料: