27

I'm working on getting the Google Place API to appear within a CardView.

The particular code I'm looking at is from GitHub, seems to be working for everyone else but I don't understand why it's throwing me an error.

This is the error I am getting:

E/AndroidRuntime: FATAL EXCEPTION: main
    Process: com.rizwanqureshi.kevstaxiscanterbury, PID: 6818
    java.lang.RuntimeException: Unable to start activity ComponentInfo{com.rizwanqureshi.kevstaxiscanterbury/com.rizwanqureshi.kevstaxiscanterbury.CustomerMapsActivity}: android.view.InflateException: Binary XML file line #50 in com.rizwanqureshi.kevstaxiscanterbury:layout/activity_customer_maps: Binary XML file line #50 in com.rizwanqureshi.kevstaxiscanterbury:layout/activity_customer_maps: Error inflating class android.fragment.app.FragmentContainerView
        at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:3270)
        at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3409)
        at android.app.servertransaction.LaunchActivityItem.execute(LaunchActivityItem.java:83)
        at android.app.servertransaction.TransactionExecutor.executeCallbacks(TransactionExecutor.java:135)
        at android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:95)
        at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2016)
        at android.os.Handler.dispatchMessage(Handler.java:107)
        at android.os.Looper.loop(Looper.java:214)
        at android.app.ActivityThread.main(ActivityThread.java:7356)
        at java.lang.reflect.Method.invoke(Native Method)
        at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:492)
        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:930)
     Caused by: android.view.InflateException: Binary XML file line #50 in com.rizwanqureshi.kevstaxiscanterbury:layout/activity_customer_maps: Binary XML file line #50 in com.rizwanqureshi.kevstaxiscanterbury:layout/activity_customer_maps: Error inflating class android.fragment.app.FragmentContainerView
     Caused by: android.view.InflateException: Binary XML file line #50 in com.rizwanqureshi.kevstaxiscanterbury:layout/activity_customer_maps: Error inflating class android.fragment.app.FragmentContainerView
     Caused by: java.lang.ClassNotFoundException: android.fragment.app.FragmentContainerView
        at java.lang.Class.classForName(Native Method)
        at java.lang.Class.forName(Class.java:454)
        at android.view.LayoutInflater.createView(LayoutInflater.java:815)
        at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:1006)
        at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:961)
        at android.view.LayoutInflater.rInflate(LayoutInflater.java:1123)
        at android.view.LayoutInflater.rInflateChildren(LayoutInflater.java:1084)
        at android.view.LayoutInflater.rInflate(LayoutInflater.java:1126)
        at android.view.LayoutInflater.rInflateChildren(LayoutInflater.java:1084)
        at android.view.LayoutInflater.rInflate(LayoutInflater.java:1126)
        at android.view.LayoutInflater.rInflateChildren(LayoutInflater.java:1084)
        at android.view.LayoutInflater.inflate(LayoutInflater.java:682)
        at android.view.LayoutInflater.inflate(LayoutInflater.java:534)
        at android.view.LayoutInflater.inflate(LayoutInflater.java:481)
        at com.android.internal.policy.PhoneWindow.setContentView(PhoneWindow.java:438)
        at android.app.Activity.setContentView(Activity.java:3324)
        at com.rizwanqureshi.kevstaxiscanterbury.CustomerMapsActivity.onCreate(CustomerMapsActivity.java:116)
        at android.app.Activity.performCreate(Activity.java:7802)
        at android.app.Activity.performCreate(Activity.java:7791)
        at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1299)
        at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:3245)
        at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3409)
        at android.app.servertransaction.LaunchActivityItem.execute(LaunchActivityItem.java:83)
        at android.app.servertransaction.TransactionExecutor.executeCallbacks(TransactionExecutor.java:135)
        at android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:95)
        at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2016)
        at android.os.Handler.dispatchMessage(Handler.java:107)
        at android.os.Looper.loop(Looper.java:214)
E/AndroidRuntime:     at android.app.ActivityThread.main(ActivityThread.java:7356)
        at java.lang.reflect.Method.invoke(Native Method)
        at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:492)
        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:930)
     Caused by: java.lang.ClassNotFoundException: Didn't find class "android.fragment.app.FragmentContainerView" on path: DexPathList[[zip file "/data/app/com.rizwanqureshi.kevstaxiscanterbury-Nkg-1mQCfbE8I1MoJKHQuA==/base.apk"],nativeLibraryDirectories=[/data/app/com.rizwanqureshi.kevstaxiscanterbury-Nkg-1mQCfbE8I1MoJKHQuA==/lib/x86, /system/lib, /system/product/lib]]
        at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:196)
        at java.lang.ClassLoader.loadClass(ClassLoader.java:379)
        at java.lang.ClassLoader.loadClass(ClassLoader.java:312)
            ... 32 more

The main takeaway is that there is an Error inflating class android.fragment.app.FragmentContainerView and that the issue is at line 50 of the XML.

This is the XML:

<FrameLayout
    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=".CustomerLogin" >


    <androidx.fragment.app.FragmentContainerView
        android:id="@+id/map"
        android:name="com.google.android.gms.maps.SupportMapFragment"
        android:layout_width="match_parent"
        android:layout_height="match_parent"/>

    <RelativeLayout
        android:layout_width="wrap_content"
        android:layout_height="wrap_content">
        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:id="@+id/buttons">
            <Button
                android:layout_weight="1"
                android:layout_width="0dp"
                android:layout_height="wrap_content"
                android:id="@+id/logout"
                android:text="logout"
                tools:ignore="ButtonStyle" />
            <Button
                android:layout_weight="1"
                android:layout_width="0dp"
                android:layout_height="wrap_content"
                android:id="@+id/history"
                android:text="history"
                tools:ignore="ButtonStyle" />
            <Button
                android:layout_weight="1"
                android:layout_width="0dp"
                android:layout_height="wrap_content"
                android:id="@+id/settings"
                android:text="Settings"
                tools:ignore="ButtonStyle" />
        </LinearLayout>

        <androidx.cardview.widget.CardView
            android:layout_below="@+id/buttons"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_margin="20sp">



//***LINE 50 WHERE THE ERROR IS***



            <android.fragment.app.FragmentContainerView
                android:id="@+id/place_autocomplete_fragment"
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                tools:ignore="ExtraText">
                android:name="com.google.android.gms.location.places.ui.PlaceAutocompleteFragment"
            </android.fragment.app.FragmentContainerView>
        </androidx.cardview.widget.CardView>
    </RelativeLayout>

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:orientation="vertical"
        android:layout_gravity="bottom">
        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:id="@+id/driverInfo"
            android:layout_gravity="bottom"
            android:orientation="horizontal"
            android:background="@android:color/white"
            android:visibility="gone">
            <LinearLayout
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:orientation="vertical"
                android:paddingLeft="40sp">
            </LinearLayout>
        </LinearLayout>
        <LinearLayout
            android:background="@android:color/white"
            android:orientation="vertical"
            android:layout_width="match_parent"
            android:layout_height="wrap_content">
        </LinearLayout>
    </LinearLayout>
</FrameLayout>

So I guess there is something wrong with the FragmentContainerView? But i'm not getting any errors in the code and nothing is coming up on Google.

I feel like maybe something is outdated rather than outright incorrect but I haven't a clue.

Thanks for any input.

riizwaan
  • 315
  • 1
  • 3
  • 6
  • Does this answer your question:- https://stackoverflow.com/questions/19874882/android-view-inflateexception-binary-xml-file-error-inflating-class-fragment – WhiteSpidy. May 25 '20 at 08:40
  • try change your android:name to class refer to this https://stackoverflow.com/a/19952291/7806581 – Ferdy Ferdy May 25 '20 at 08:49
  • `ClassNotFoundException: android.fragment.app.FragmentContainerView` – You have a typo in that layout tag. You're missing the `x` in `androidx`: ` – Mike M. Jul 11 '20 at 11:13
  • 1
    @riizwaan were you able to resolve this? getting the same error any insights would be helpful – Gauri Gadkari Oct 02 '20 at 21:43
  • 1
    Did you find an answer for that error? I have the same problem which you had – MadhanMohan May 04 '21 at 09:25

15 Answers15

38

just try to define your startDestination in your navigation xml !

imansdn
  • 968
  • 1
  • 7
  • 17
8

You should implement new androidx.fragment dependencies to use FragmentContainerView. It is already added since version 1.2.0. You can check here

implementation "androidx.fragment:fragment:1.2.5"
Công Hải
  • 4,961
  • 3
  • 14
  • 20
  • 6
    For Kotlin: `implementation 'androidx.fragment:fragment-ktx:1.2.5'`. – CoolMind Nov 29 '20 at 20:40
  • 4
    Why does this work? You'd think Fragments are very much a part of the standard Android libs. – SMBiggs Sep 06 '21 at 14:04
  • @SMBiggs no, Android is moving to a model where SDK classes are provided in (static) libraries, not by the platform they run on. So there's an `android.app.Fragment` that's deprecated, and an `androidx.fragment.app.Fragment` that you should use in its place. – Jeffrey Blattman Aug 04 '23 at 16:34
7

In my case, I had a Model which was used as arguments but I had not implemented Serializable and Parcelable implementaion.

Faizan Haidar Khan
  • 1,099
  • 1
  • 15
  • 20
6

This problem was created for me as well. The reason was two mistakes.

1.I did not add startDestination in nav graph .

2.I did not add @AndroidEntryPoint annotation in MainActivitey .

Asghar Hosseini
  • 239
  • 1
  • 5
  • 14
5

This error will only occur after you have added ProGuard & R8 to your project. To fix it, add the following two lines in proguard-rule.pro:

-keepnames class androidx.navigation.fragment.NavHostFragment
-keep class * extends androidx.fragment.app.Fragment{}
Dada
  • 6,313
  • 7
  • 24
  • 43
Gaurav mishra
  • 53
  • 1
  • 4
4

For me it was a typo within one of the fragments the navGraph, in the class path of the android:name attribute.. Adding a wrong path for the fragment class doesn't provide a compile time error, instead it raises android.view.InflateException...Error inflating class android.fragment.app.FragmentContainerView

So, make sure to have a correct packaging path for your fragments in android:name

<?xml version="1.0" encoding="utf-8"?>
<navigation 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:id="@+id/nav_graph.xml"
    app:startDestination="@id/mainFragment">

    <fragment
        android:id="@+id/mainFragment"
        android:name="com.example.android....MainFragment"  // <<<< This must be a correct path 
        android:label="main_fragment"
    </fragment>

</navigation>
Zain
  • 37,492
  • 7
  • 60
  • 84
2

If it is Due to Proguard Then add few lines

In proguard-rules.pro file

....
# for FragmentContainerView error
-keepnames class androidx.navigation.fragment.NavHostFragment
-keep class * extends androidx.fragment.app.Fragment{}
Rahul Khatri
  • 1,502
  • 2
  • 13
  • 25
1

Your activity must be a child of FragmentActivity to use androidx.fragment.app.FragmentContainerView either you extend the FragmentActivity or the AppCompatActivity which is a child FragmentActivity class. It is recommended to extend the AppCompatActivity.

see: https://www.tutorialguruji.com/android/trying-to-use-navhostfragment-and-im-getting-an-error-error-inflating-class-androidx-fragment-app-fragmentcontainerview/

Erik Fors
  • 11
  • 1
  • 1
    While this link may answer the question, it is better to include the essential parts of the answer here and provide the link for reference. Link-only answers can become invalid if the linked page changes. - [From Review](/review/late-answers/30160133) – Lajos Arpad Oct 23 '21 at 23:29
1

In my case, despite the same error, reason was different. However this info about adding some rules to proguard-rules.pro pointed me into the right direction. This, and some other clues in error log about problems with argument in navigation XML file. Eventually I found that it was problem with using my own classes in argument. And I don't mean the class of argument, but the fact that this class also used some of my other classes. And it was enough to add rules for each of these other classes:

-keepnames class <MyClass>
...
1

In my case I looked deeper inside my stacktrace and found this line: Caused by: java.lang.IllegalStateException: FragmentContainerView must have an android:id to add Fragment MyFragment. Giving it an id and specifying tools:layout fixed problem

Savvasenok
  • 31
  • 6
0

Probably after Refactor->Remove unused resources you can lost id from your androidx.fragment.app.FragmentContainerView - bring it back

nicolas asinovich
  • 3,201
  • 3
  • 27
  • 37
0

If you have done all the solutions and still the problem stands maybe you should check if your fragment constructor is empty.

StackOverflower
  • 369
  • 2
  • 12
0
  1. First add fragment dependency- latest version

implementation "androidx.fragment:fragment:1.5.7"

  1. If you getting error in xml. Click on that and scroll down click on "Do not warn" your view will be visible. enter image description here
TexD
  • 162
  • 1
  • 10
0
if still this issue not resolved.

Please check if you your activity extending FragmentActivity or not.

suppose your activity is CustomerMapsActivity.

Need to check if CustomerMapsActivity extends FragmentActivity or not.
if CustomerMapsActivity extends BaseActivity, check BaseActivity should extends FragmentActivity.

To inflate this "android.fragment.app.FragmentContainerView" we need FragmentActivity
Manoj Behera
  • 2,736
  • 22
  • 13
0

In my case the error was related to Serializable and Parcelable. To fix it, add the following two lines in proguard-rule.pro:

-keepnames class * extends android.os.Parcelable
-keepnames class * extends java.io.Serializable