1

i have checked all similar questions(This and others ) but still couldn't figure out the cause of the error, it keeps shutting down at some point during run time...

CategoryDetailFragment.java

/**
 * A simple {@link Fragment} subclass.
 */
public class CategoryDetailFragment extends Fragment implements View.OnClickListener{
    @BindView(R.id.categoryNameTextView) TextView mCategoryNameTextView;
    @BindView(R.id.addPostButton) Button mAddPostButton;
    private Category mCategory;

    public static CategoryDetailFragment newInstance(Category category) {
        CategoryDetailFragment categoryDetailFragment = new CategoryDetailFragment();
        Bundle args = new Bundle();
        args.putParcelable("category", Parcels.wrap(category));
        categoryDetailFragment.setArguments(args);
        return categoryDetailFragment;
    }

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        mCategory = Parcels.unwrap(getArguments().getParcelable("category"));
    }


    @Override
    public View onCreateView(@NonNull LayoutInflater inflater, ViewGroup container,
                             Bundle savedInstanceState) {
        View view = inflater.inflate(R.layout.fragment_category_detail, container, false);
        ButterKnife.bind(this, view);
        mAddPostButton.setOnClickListener(this);

        mCategoryNameTextView.setText(mCategory.getName());
        return view;
    }

fragment_category_detail.xml

<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.epicodus.talkaboutit.ui.CategoryDetailFragment">

    <TextView
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:text="Category Name"
        android:id="@+id/categoryNameTextView"
        android:layout_gravity="center"
        android:textAlignment="center"
        android:paddingTop="10dp"
        android:textSize="20sp"/>

    <fragment
        android:name = "com.epicodus.talkaboutit.ui.PostListFragment"
        android:id="@+id/postListFragment"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        tools:layout="@layout/fragment_post_list"
        android:layout_below="@+id/categoryNameTextView"
        android:layout_alignParentLeft="true"
        android:layout_alignParentStart="true"
        android:layout_marginTop="69dp"
        android:layout_above="@+id/addPostButton" />

    <Button
        style="?android:attr/buttonStyleSmall"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:text="Add Post"
        android:id="@+id/addPostButton"
        android:layout_alignParentBottom="true"
        android:layout_alignParentLeft="true"
        android:layout_alignParentStart="true" />

</RelativeLayout>

error:

D/AndroidRuntime: Shutting down VM
E/AndroidRuntime: FATAL EXCEPTION: main
    Process: com.epicodus.talkaboutit, PID: 27394
    android.view.InflateException: Binary XML file line #17: Binary XML file line #17: Error inflating class fragment
        at android.view.LayoutInflater.inflate(LayoutInflater.java:551)
        at android.view.LayoutInflater.inflate(LayoutInflater.java:429)
        at com.epicodus.talkaboutit.ui.CategoryDetailFragment.onCreateView(CategoryDetailFragment.java:57)
        at androidx.fragment.app.Fragment.performCreateView(Fragment.java:2439)
        at androidx.fragment.app.FragmentManagerImpl.moveToState(FragmentManager.java:1460)
        at androidx.fragment.app.FragmentManagerImpl.moveFragmentToExpectedState(FragmentManager.java:1784)
        at androidx.fragment.app.FragmentManagerImpl.moveToState(FragmentManager.java:1852)
        at androidx.fragment.app.BackStackRecord.executeOps(BackStackRecord.java:802)
        at androidx.fragment.app.FragmentManagerImpl.executeOps(FragmentManager.java:2625)
        at androidx.fragment.app.FragmentManagerImpl.executeOpsTogether(FragmentManager.java:2411)
        at androidx.fragment.app.FragmentManagerImpl.removeRedundantOperationsAndExecute(FragmentManager.java:2366)
        at androidx.fragment.app.FragmentManagerImpl.execSingleAction(FragmentManager.java:2243)
        at androidx.fragment.app.BackStackRecord.commitNowAllowingStateLoss(BackStackRecord.java:654)
        at androidx.fragment.app.FragmentPagerAdapter.finishUpdate(FragmentPagerAdapter.java:146)
        at androidx.viewpager.widget.ViewPager.populate(ViewPager.java:1244)
        at androidx.viewpager.widget.ViewPager.populate(ViewPager.java:1092)
        at androidx.viewpager.widget.ViewPager.onMeasure(ViewPager.java:1622)
        at android.view.View.measure(View.java:20151)
        at android.widget.RelativeLayout.measureChildHorizontal(RelativeLayout.java:716)
        at android.widget.RelativeLayout.onMeasure(RelativeLayout.java:462)
        at android.view.View.measure(View.java:20151)
        at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:6330)
        at android.widget.FrameLayout.onMeasure(FrameLayout.java:194)
        at androidx.appcompat.widget.ContentFrameLayout.onMeasure(ContentFrameLayout.java:143)
        at android.view.View.measure(View.java:20151)
        at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:6330)
        at androidx.appcompat.widget.ActionBarOverlayLayout.onMeasure(ActionBarOverlayLayout.java:401)
        at android.view.View.measure(View.java:20151)
        at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:6330)
        at android.widget.FrameLayout.onMeasure(FrameLayout.java:194)
        at android.view.View.measure(View.java:20151)
        at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:6330)
        at android.widget.LinearLayout.measureChildBeforeLayout(LinearLayout.java:1464)
        at android.widget.LinearLayout.measureVertical(LinearLayout.java:747)
        at android.widget.LinearLayout.onMeasure(LinearLayout.java:629)
        at android.view.View.measure(View.java:20151)
        at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:6330)
        at android.widget.FrameLayout.onMeasure(FrameLayout.java:194)
        at com.android.internal.policy.PhoneWindow$DecorView.onMeasure(PhoneWindow.java:3158)
        at android.view.View.measure(View.java:20151)
        at android.view.ViewRootImpl.performMeasure(ViewRootImpl.java:2594)
        at android.view.ViewRootImpl.measureHierarchy(ViewRootImpl.java:1549)
        at android.view.ViewRootImpl.performTraversals(ViewRootImpl.java:1841)
        at android.view.ViewRootImpl.doTraversal(ViewRootImpl.java:1437)
        at android.view.ViewRootImpl$TraversalRunnable.run(ViewRootImpl.java:7397)
        at android.view.Choreographer$CallbackRecord.run(Choreographer.java:920)
        at android.view.Choreographer.doCallbacks(Choreographer.java:695)
        at android.view.Choreographer.doFrame(Choreographer.java:631)
        at android.view.Choreographer$FrameDisplayEventReceiver.run(Choreographer.java:906)
        at android.os.Handler.handleCallback(Handler.java:739)
        at android.os.Handler.dispatchMessage(Handler.java:95)
        at android.os.Looper.loop(Looper.java:158)
        at android.app.ActivityThread.main(ActivityThread.java:7224)
        at java.lang.reflect.Method.invoke(Native Method)
        at com.android.interna
I/Process: Sending signal. PID: 27394 SIG: 9
Application terminated.

the error seems to come from this line

View view = inflater.inflate(R.layout.fragment_category_detail, container, false);

I've tried all i could, any help is appreciated...

X-Black...
  • 1,376
  • 2
  • 20
  • 28

2 Answers2

3

Check whether you are saved the layout file of the fragment as V-24. This may cause the problem in inflating the view if your minimum SDK version less than 24. As of I Know, View inflation error in android is happening mostly due to version-specific layout or drawable.

Pradeep
  • 798
  • 1
  • 7
  • 18
0

Its is getting crash because it is not able to find the fragment using class, you should mention the fragment name like below

Change this one

<fragment
        class = "com.epicodus.talkaboutit.ui.PostListFragment"
        android:id="@+id/postListFragment"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        tools:layout="@layout/fragment_post_list"
        android:layout_below="@+id/categoryNameTextView"
        android:layout_alignParentLeft="true"
        android:layout_alignParentStart="true"
        android:layout_marginTop="69dp"
        android:layout_above="@+id/addPostButton" />

to this

 <fragment
            android:name = "com.epicodus.talkaboutit.ui.PostListFragment"
            android:id="@+id/postListFragment"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            tools:layout="@layout/fragment_post_list"
            android:layout_below="@+id/categoryNameTextView"
            android:layout_alignParentLeft="true"
            android:layout_alignParentStart="true"
            android:layout_marginTop="69dp"
            android:layout_above="@+id/addPostButton" />
Rahul
  • 1,380
  • 1
  • 10
  • 24