0

Am facing the below error,

Fatal Exception: java.lang.RuntimeException: Unable to start activity ComponentInfo{com.test/com.activities.ViewActivity}: android.view.InflateException: Binary XML file line #29: Binary XML file line #29: Error inflating class fragment at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2984) at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3045) at android.app.ActivityThread.-wrap14(ActivityThread.java) at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1642) at android.os.Handler.dispatchMessage(Handler.java:102) at android.os.Looper.loop(Looper.java:154) at android.app.ActivityThread.main(ActivityThread.java:6776) at java.lang.reflect.Method.invoke(Method.java) at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1520) at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1410)

XML File,

<?xml version="1.0" encoding="utf-8"?>
<android.support.design.widget.CoordinatorLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fitsSystemWindows="true"
tools:context="com.activities.ViewActivity">
<android.support.design.widget.AppBarLayout
    android:layout_height="wrap_content"
    android:layout_width="match_parent"
    android:theme="@style/AppTheme.AppBarOverlay">

    <android.support.v7.widget.Toolbar
        android:id="@+id/toolbar"
        android:layout_width="match_parent"
        android:layout_height="?attr/actionBarSize"
        android:background="?attr/colorPrimary"
        app:popupTheme="@style/AppTheme.PopupOverlay" />

</android.support.design.widget.AppBarLayout>
<FrameLayout
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    app:layout_behavior="@string/appbar_scrolling_view_behavior"
    >

    <fragment class="com.fragments.ViewFragment"
        android:id="@+id/details_frag"
        tools:layout="@layout/fragment_view"
        android:layout_width="match_parent"
        android:layout_height="match_parent">
    </fragment>

</FrameLayout>
</android.support.design.widget.CoordinatorLayout>
4
  • can you post your java code too Commented May 18, 2018 at 4:52
  • com.fragments.ViewFragment does exist this class ? Commented May 18, 2018 at 4:54
  • yes, it does exist Commented May 18, 2018 at 7:08
  • Look further on in the stack trace for the root Exception. Commented May 18, 2018 at 9:11

2 Answers 2

2

The stacktrace says “Error inflating class fragment”, so there must be an issue with your fragment tag in the layout file.The XML should look like this:

  <fragment 
        xmlns:android="http://schemas.android.com/apk/res/android"
        xmlns:tools="http://schemas.android.com/tools"
        android:name="com.fragments.ViewFragment"
        android:id="@+id/details_frag"
        tools:layout="@layout/fragment_view"
        android:layout_width="match_parent"
        android:layout_height="match_parent">
  </fragment>

And Check the name attribute. Verify that your fragment lives in the package your specified and has the exact name that you specified.

If that doesn’t work, please post the full stacktrace and I’ll help to troubleshoot.

I hope it will help for you

Sign up to request clarification or add additional context in comments.

Comments

0

Use the FrameLayout as your FragmentHolder and add the fragment dynamically using the FragmentTransaction in your Activity to this fragmentHolder.

Remove the fragment inside looks like thats having issues as per your build.gradle file.

Please kindly ensure that you add it as per your requirements such as adding it to the backstack and all.

Comments

Your Answer

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

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.