简体   繁体   中英

Can't cast MapView

I am working on android application project, but I keep having problem with casting MapView. From the logcat,

Caused by: java.lang.classCastException : com.google.android.maps.MapView cannot be cast to 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 . 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.

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.

Check your import statements, and check your MapView declaration. Make sure the import matches the view.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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