0

I am working on a project that requires fragments. Whenever I test run the project, in my fragment class, I get an exception pointing to the inflaterline of my oncreateview method, like shown below.

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)

This is the snippet of my fragment class

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); 
    }

}

My layout file is shown below:

<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"/>

What could be causing this, as the app does not even load the first screen due to this exception.

4
  • show fragment_hygiene_clone xml Jan 6, 2017 at 1:44
  • Do you have compile "com.android.support:design:X.X.X" in ur gradlew ?
    – N Jay
    Jan 6, 2017 at 1:55
  • @ρяσѕρєяK, that's the layout file shown above. Jan 6, 2017 at 2:12
  • I will remove every single control from xml file to see if program runs well without it. if good, then problem goes directly to this control. if remains the same after removing all controls, then the code must contains error, not the xml file. Jan 6, 2017 at 3:05

1 Answer 1

0

Cause you don't have dependencies relate to android.support.design.widget.FloatingActionButton. Try add -- compile 'com.android.support:design:23.2.0' in your build.gradle

4
  • I have added the dependency but the problem still persists. Jan 6, 2017 at 2:24
  • 1.press Ctrl and click the android.support.design.widget.FloatingActionButton in your xml file,can you jump to the FloatingActionButton.java file ? 2.Try Clean Project?
    – mrz
    Jan 6, 2017 at 2:39
  • I've tried cleaning the project and running the app again. The same error shows. Jan 6, 2017 at 15:37
  • did you got a NoSuchMethodError too?See this:stackoverflow.com/questions/39916850/…
    – mrz
    Jan 9, 2017 at 2:09

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.