当前位置: 首页 > 知识库问答 >
问题:

如何处理Android.View.InflateException?当我试图打开地图时,我遇到了这个错误

冯良才
2023-03-14
     android.view.InflateException: Binary XML file line #12 in com.transasia.ctrack:layout/agent_locationmap_layout: Binary XML file line #12 in com.transasia.ctrack:layout/agent_locationmap_layout: Error inflating class androidx.fragment.app.FragmentContainerView
        Caused by: android.view.InflateException: Binary XML file line #12 in com.transasia.ctrack:layout/agent_locationmap_layout: Error inflating class androidx.fragment.app.FragmentContainerView
        Caused by: java.lang.ClassCastException: com.google.android.gms.location.places.ui.PlaceAutocompleteFragment cannot be cast to androidx.fragment.app.Fragment
            at androidx.fragment.app.Fragment.instantiate(Fragment.java:548)
            at androidx.fragment.app.FragmentContainer.instantiate(FragmentContainer.java:57)
            at androidx.fragment.app.FragmentManager$3.instantiate(FragmentManager.java:390)
            at androidx.fragment.app.FragmentContainerView.<init>(FragmentContainerView.java:161)
            at androidx.fragment.app.FragmentLayoutInflaterFactory.onCreateView(FragmentLayoutInflaterFactory.java:51)
            at androidx.fragment.app.FragmentController.onCreateView(FragmentController.java:135)
            at androidx.fragment.app.FragmentActivity.dispatchFragmentsOnCreateView(FragmentActivity.java:356)
            at androidx.fragment.app.FragmentActivity.onCreateView(FragmentActivity.java:335)
            at android.view.LayoutInflater.tryCreateView(LayoutInflater.java:1069)
            at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:997)
            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.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.transasia.ctrackvp.agentfold.AgentAndHospitalLocationActivity.onCreate(AgentAndHospitalLocationActivity.java:71)
            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)
            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)
    2021-05-04 15:08:01.216 13007-13007/com.transasia.ctrack E/AndroidRuntime: FATAL EXCEPTION: main
        Process: com.transasia.ctrack, PID: 13007
        java.lang.RuntimeException: Unable to start activity ComponentInfo{com.transasia.ctrack/com.transasia.ctrackvp.agentfold.AgentAndHospitalLocationActivity}: android.view.InflateException: Binary XML file line #12 in com.transasia.ctrack:layout/agent_locationmap_layout: Binary XML file line #12 in com.transasia.ctrack:layout/agent_locationmap_layout: Error inflating class androidx.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 #12 in com.transasia.ctrack:layout/agent_locationmap_layout: Binary XML file line #12 in com.transasia.ctrack:layout/agent_locationmap_layout: Error inflating class androidx.fragment.app.FragmentContainerView
         Caused by: android.view.InflateException: Binary XML file line #12 in com.transasia.ctrack:layout/agent_locationmap_layout: Error inflating class androidx.fragment.app.FragmentContainerView
         Caused by: java.lang.ClassCastException: com.google.android.gms.location.places.ui.PlaceAutocompleteFragment cannot be cast to androidx.fragment.app.Fragment
            at androidx.fragment.app.Fragment.instantiate(Fragment.java:548)
            at androidx.fragment.app.FragmentContainer.instantiate(FragmentContainer.java:57)
            at androidx.fragment.app.FragmentManager$3.instantiate(FragmentManager.java:390)
            at androidx.fragment.app.FragmentContainerView.<init>(FragmentContainerView.java:161)
            at androidx.fragment.app.FragmentLayoutInflaterFactory.onCreateView(FragmentLayoutInflaterFactory.java:51)
            at androidx.fragment.app.FragmentController.onCreateView(FragmentController.java:135)
            at androidx.fragment.app.FragmentActivity.dispatchFragmentsOnCreateView(FragmentActivity.java:356)
            at androidx.fragment.app.FragmentActivity.onCreateView(FragmentActivity.java:335)
            at android.view.LayoutInflater.tryCreateView(LayoutInflater.java:1069)
            at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:997)
            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.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.transasia.ctrackvp.agentfold.AgentAndHospitalLocationActivity.onCreate(AgentAndHospitalLocationActivity.java:71)
            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)

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

    <LinearLayout
        android:id="@+id/ll_place"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:orientation="vertical">

        <androidx.fragment.app.FragmentContainerView  // showing error in this part <<<<<--------
            android:id="@+id/place_fragment_map"
            android:name="com.google.android.gms.location.places.ui.PlaceAutocompleteFragment"
            android:layout_width="match_parent"
            android:layout_height="wrap_content" />
    </LinearLayout>

    <androidx.coordinatorlayout.widget.CoordinatorLayout
        android:id="@+id/main_content"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_below="@+id/ll_place">

        <androidx.fragment.app.FragmentContainerView
            android:id="@+id/mapp"
            android:name="com.google.android.gms.maps.SupportMapFragment"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            tools:context="com.transasia.ctrackvp.agentfold.AgentAndHospitalLocationActivity" />

    </androidx.coordinatorlayout.widget.CoordinatorLayout>

    <Button
        android:id="@+id/btn_route"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentRight="true"
        android:layout_alignParentBottom="true"
        android:text="Direction" />

</RelativeLayout>

    Java:
       @Override
    
        protected void onCreate(Bundle savedInstanceState) {
            try {
                super.onCreate(savedInstanceState);
                setContentView(R.layout.agent_locationmap_layout); //Error in this part<<<----
            }catch (Exception e){
                Log.e(TAG, "onCreateView", e);
                throw e;
            }

共有1个答案

督飞鸣
2023-03-14

尝试使用此代码

 android:name="com.google.android.gms.location.places.ui.SupportPlaceAutocompleteFragment" />

而且

SupportPlaceAutocompleteFragment placeFragmentMap= (SupportPlaceAutocompleteFragment)
        getChildFragmentManager()
                .findFragmentById(R.id.place_fragment_map);

而不是这样

<androidx.fragment.app.FragmentContainerView
 android:id="@+id/place_fragment_map"
 android:name="com.google.android.gms.location.places.ui.PlaceAutocompleteFragment"
 android:layout_width="match_parent"
 android:layout_height="wrap_content" />
 类似资料:
  • 下面是我的代码: java.lang.runtimeException:无法启动活动ComponentInfo{com.example.auditoriamedica/com.example.auditoriamedica.views.principal}:java.lang.IllegalStateException:findViewById(r.id.nav_view)在Android.app

  • 以下是相关错误及其显示: JAVAexe不是可识别为内部或外部命令、可操作或外部命令的文件 errorlevel=9009

  • 错误:任务“app:transformClassesWithDexForDebug”的执行失败 com.android.build.api.transform。TransformException:com.android.ide.common.process。ProcessException:org.gradle.process.internal。ExecException:处理C:\Progra

  • 失败:生成失败,出现异常。 问题:配置根项目“android”时出现问题 无法解析配置“classpath”的所有项目。找不到组织。喷气式飞机。kotlin:kotlin gradl电子插件:1.3.50。在以下位置搜索:-https://dl.google.com/dl/android/maven2/org/jetbrains/kotlin/kotlin-gradle-plugin/1.3.50

  • 我正在尝试将从数据库接收到的列表对象转换为Json,但当我尝试转换时,我得到了。 这是我的代码: 想法是,我从数据库中检索一个Orderobjects列表,将其传递给dataTableResult,并将其发送到前端由Jquerydatatable显示,我得到了这些列表,但是当我尝试使用GSON()来尝试转换orederList或dataTableResult时,它会抛出一个错误。我切换到flexJ

  • 问题检测到端口3306M被C程序文件使用(x86)MySQL MySQL Server 5.0ibinimysqld如果没有配置的空闲端口,MySQL将无法启动! 您需要卸载/禁用/重新配置阻塞应用程序 或重新配置MySQL和控制面板以侦听不同的端口