简体   繁体   English

无法投放MapView

[英]Can't cast MapView

I am working on android application project, but I keep having problem with casting MapView. 我正在从事android应用程序项目,但是我在投射MapView时一直遇到问题。 From the logcat, 从logcat,

Caused by: java.lang.classCastException : com.google.android.maps.MapView cannot be cast to com.google.android.gms.maps.MapView. 造成原因:java.lang.classCastException:com.google.android.maps.MapView无法转换为com.google.android.gms.maps.MapView。

And this is my code for casting 这是我的转换代码

MapView mapView = (MapView) findViewById(R.id.mapView);

any suggestion? 有什么建议吗?

Make sure you only import one MapView , and make sure its type matches the one returned by findViewById . 确保仅导入一个MapView ,并确保其类型与findViewById返回的类型匹配。 This is probably caused by an improper import. 这可能是由于进口不当造成的。 If your view at R.id.mapView is different than the one you're importing, you won't be able to cast it. 如果您在R.id.mapView上的视图与要导入的视图不同,则将无法对其进行投射。

So, if your display has a com.google.android.maps.MapView but your code imports com.google.android.gms.maps.MapView , you won't be able to cast. 因此,如果您的显示器具有com.google.android.maps.MapView但是您的代码导入了com.google.android.gms.maps.MapView ,则将无法进行投射。

Check your import statements, and check your MapView declaration. 检查您的导入语句,并检查您的MapView声明。 Make sure the import matches the view. 确保导入与视图匹配。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM