在片段类中夸大异常

时间:2017-01-06 01:42:58

标签: java android android-fragments inflate-exception binary-xml

我正在开发一个需要片段的项目。每当我测试运行项目时,在我的fragment类中,我得到一个异常,指向我的oncreateview方法的inflaterline,如下所示。

Process: com.example.joey.maranathahealthblog, PID: 29380
    android.view.InflateException: Binary XML file line #12: Error inflating class <unknown>
    at android.view.LayoutInflater.createView(LayoutInflater.java:633)
    at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:743)
    at android.view.LayoutInflater.rInflate(LayoutInflater.java:806)
    at android.view.LayoutInflater.inflate(LayoutInflater.java:504)
    at android.view.LayoutInflater.inflate(LayoutInflater.java:414)
    at com.example.joey.maranathahealthblog.BlogTabs.TabsFragments.HygieneClone.onCreateView(HygieneClone.java:27)

这是我的片段类的片段

public class HygieneClone extends Fragment {


    public HygieneClone() {
        // Required empty public constructor
    }


    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
                             Bundle savedInstanceState) {
        // Inflate the layout for this fragment

        //  error occurs here
        return inflater.inflate(R.layout.fragment_hygiene_clone, container, false); 
    }

}

我的布局文件如下所示:

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context="com.example.joey.maranathahealthblog.BlogTabs.TabsFragments.HygieneClone">

<android.support.v7.widget.RecyclerView
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:id="@+id/hygiene_recyclerView"/>

<android.support.design.widget.FloatingActionButton
    android:id="@+id/newPost_Fab"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:backgroundTint="@color/colorPrimary"
    android:src="@drawable/ic_add_black_24dp"
    android:layout_alignParentBottom="true"
    android:layout_alignParentRight="true"
    android:layout_marginRight="20dp"
    android:layout_marginBottom="40dp"/>

由于此异常,应用甚至无法加载第一个屏幕,因此可能导致此问题。

1 个答案:

答案 0 :(得分:0)

因为您没有与android.support.design.widget.FloatingActionButton相关的依赖项。 尝试添加 - 编译&#39; com.android.support:design:23.2.0&#39; 在build.gradle中

相关问题