我正在尝试实现地图,但遇到了不可转换类型的错误;无法将android.support.v4.app.Fragment转换为com.Google.androID.gms.maps.SupportMapFragment
我看到了一些资源,但对我没有用
import androID.support.v4.app.FragmentActivity;import androID.os.Bundle;import com.Google.androID.gms.maps.CameraUpdateFactory;import com.Google.androID.gms.maps.GoogleMap;import com.Google.androID.gms.maps.OnMapReadyCallback;import com.Google.androID.gms.maps.SupportMapFragment;import com.Google.androID.gms.maps.model.LatLng;import com.Google.androID.gms.maps.model.MarkerOptions;public class MapsActivity extends FragmentActivity implements OnMapReadyCallback {private GoogleMap mMap;@OverrIDeprotected voID onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentVIEw(R.layout.activity_maps); // Obtain the SupportMapFragment and get notifIEd when the map is ready to be used. SupportMapFragment mapFragment = (SupportMapFragment) getSupportFragmentManager() .findFragmentByID(R.ID.map); mapFragment.getMapAsync(this);}
Inconvertible types; cannot cast ‘androID.support.v4.app.Fragment’ to
‘com.Google.androID.gms.maps.SupportMapFragment’
解决方法:
按照Google Play services Android release notes for play-services-maps:17.0.0
:
Warning: This release is a MAJOR version update and breaking change.
Update your app to use Jetpack (AndroIDX); follow the instructions in 07001.
Maps 17.0.0已切换到AndroidX.这意味着SupportMapFragment现在扩展了androidx.fragment.app.Fragment
,而不是等效的Support library.您需要切换回16.1.0或将您的应用迁移到AndroIDX.
以上是内存溢出为你收集整理的java-不可转换类型无法强制转换全部内容,希望文章能够帮你解决java-不可转换类型无法强制转换所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)