【问题标题】:inconvertible types; cannot cast android.support.v4.app.fragment [duplicate]不可转换的类型;无法投射 android.support.v4.app.fragment [重复]
【发布时间】:2019-07-10 05:20:01
【问题描述】:

我正在关注 Google 地图文档,但遇到了这个错误。我只是想知道我在做什么磨损g

SupportMapFragment mapFragment = (SupportMapFragment) getSupportFragmentManager()
            .findFragmentById(R.id.map);

这是错误

'不可转换的类型不能转换 android.support.v4.app.fragment'

默认情况下创建Google Maps Activity 后,我就会收到此错误。花了 3 天的时间研究它,但仍然无法找到解决这个小问题的任何方法。

【问题讨论】:

    标签: android google-maps-api-3


    【解决方案1】:

    在新Google Play services play-services-maps:17.0.0:

    17.0.0 版本的 Google 地图已切换到 AndroidX。这意味着 SupportMapFragment 现在扩展了 androidx.fragment.app.Fragment,而不是支持库等效项。

    警告:此版本是主要版本更新和重大更改。

    • 更新您的应用以使用 Jetpack (AndroidX);按照Migrating to AndroidX 中的说明进行操作。

    您需要切换回 16.1.0 或将您的应用迁移到 AndroidX。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2014-06-03
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-03-06
      • 2012-02-18
      相关资源
      最近更新 更多