java - 膨胀类 android.fragment.app.FragmentContainerView 时出错,有人可以告诉我我缺少什么吗

标签 java android android-fragments google-places-api

我正在努力让 Google Place API 显示在 CardView 中。

我正在查看的特定代码来自 GitHub,似乎对其他人都有效,但我不明白为什么它会抛出错误。

这是我收到的错误:

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

主要的结论是,在 android.fragment.app.FragmentContainerView 类膨胀时出现错误,问题出在 XML 的第 50 行。

这是 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>

所以我猜 FragmentContainerView 有问题?但我在代码中没有收到任何错误,Google 上也没有任何结果。

我觉得也许有些东西已经过时了,而不是完全错误,但我没有任何线索。

感谢您的任何意见。

最佳答案

尝试在导航 xml 中定义 startDestination !

关于java - 膨胀类 android.fragment.app.FragmentContainerView 时出错,有人可以告诉我我缺少什么吗,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/61998629/

相关文章:

java - 尝试更改 ByteArrayOutputStream 的 FOR 循环中的值

建立连接后,通过 WifiNetworkSpecifier 的 Android Q Wifi 连接立即失去连接

java - 我的应用程序在横向 View 中困惑

android - 更改PreferenceFragment的背景颜色

java - 我应该使用 MapView 还是 Map Intent?

java - 如何在电子邮件客户端和 HTML 网页之间保留 HTML/CSS 格式?

Mac 上的 Java rxtx lib segv 错误

Android Material 设计 - LinearLayout elevation

android - EditText 中的 "word-wrap: break-word"

android - fragment 中带有选项卡的抽屉导航