error while inflating XML in Google maps fragment

夙愿已清 提交于 2019-12-04 06:58:39

Error inflating class fragment usually comes when you are trying to use the native API Level 11 version of fragments -- which your source code is doing -- but are trying to run it on an older version of Android. In order to use <fragment> on API Level 10 and below, you have to use the Android Support package's backport of fragments:

  • add the Android Support package to your project
  • inherit from FragmentActivity instead of Activity
  • use SupportMapFragment rather than MapFragment
  • change anything else that now differs based upon this backport

Or, you can set your android:minSdkVersion to 11 or higher, and run your current code, just only on newer devices.

You can read more about the Android Support package in the documentation.

I was getting same error. Check that you run it on real device.and atatch google play services library in following way. project_properties->android-> Library then add google play lib there..

again make libs folder copy android support v4.jar and google_play_services.jar and then right click to each file and select build to path..

also check your api key is for com.example.com.mapsdemo package..for every package new api key is to be generated..

and use SupportMapFragment instead on MapFragment in your XML file.

this solved my problem.

Hope this solve your problem.

A lot of questions about this problem, and after twi days, my solution is simple: you have to compile your project using Project Build Target Google API. I feel so stupid about it.

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