Android Google Maps V2 Caused by: java.lang.ClassCastException: com.google.android.gms.maps.SupportMapFragment cannot be cast to android.app.Fragment

谁说我不能喝 提交于 2019-12-08 20:52:35

Switch super.onCreate first, then setContentView.

This is because super.onCreate calls the framework's Activity.onCreate to allocate the resources needed to inflate any layouts. Hence , must be called before inflating any layouts, xml/programmatic.

ritesh4326

Change your code like this :

 public class MainActivity extends FragmentActivity  {

     private GoogleMap map;
     private LatLng ltlng;

     @Override
     protected void onCreate(Bundle savedInstanceState) {

          super.onCreate(savedInstanceState);

          setContentView(R.layout.activity_main);

      }
}
Hsm

Check the answer of Bhavesh Patadiya, https://stackoverflow.com/a/18227605/2684720

as you are extending FragmentActivity which indicates you are using Support library v4 compatible with lower version of android. Replace MapFragment with SupportMapFragment inside your xml file. SupportMapFragment is the one to use with the Android Support package. MapFragment is for the native API Level 11 version of fragments.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!