Map Fragment not working in Android4.4 kitkat

我与影子孤独终老i 提交于 2019-12-11 08:34:54

问题


I am facing a wierd problem in Android kitkat. I am not able to use map fragments(support map fragment too). I used the following code:

<fragment
    android:id="@+id/fragment1"
    android:name="com.google.android.gms.maps.SupportMapFragment"
    android:layout_width="wrap_content"
    android:layout_height="match_parent"
    android:layout_above="@+id/imageView1"
    android:layout_alignParentLeft="true"
    android:layout_below="@+id/linearLayout1" />

My application works in api level 18(Jellybean) but when compiled with kitkat it gives the following error: Error inflating class fragment!

Logcat output:

11-14 07:12:12.039: E/AndroidRuntime(1068):     at dalvik.system.NativeStart.main(Native Method)

11-14 07:12:12.039: E/AndroidRuntime(1068): Caused by: android.view.InflateException: Binary XML file line #96: Error inflating class fragment

11-14 07:12:12.039: E/AndroidRuntime(1068):     at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:713)

11-14 07:12:12.039: E/AndroidRuntime(1068):     at android.view.LayoutInflater.rInflate(LayoutInflater.java:755)

11-14 07:12:12.039: E/AndroidRuntime(1068):     at android.view.LayoutInflater.inflate(LayoutInflater.java:492)

11-14 07:12:12.039: E/AndroidRuntime(1068):     at android.view.LayoutInflater.inflate(LayoutInflater.java:397)

11-14 07:12:12.039: E/AndroidRuntime(1068):     at android.view.LayoutInflater.inflate(LayoutInflater.java:353)

回答1:


on nexus 5 device there are incompatible support and play services libraries, if you are using them in your project (either in libs for support-v4 or project libraries for the others) you can delete the related <uses-library ... /> tags from AndroidManifest.xml since the necessary bytecode should already be included in your app.
Doing this fixed the problem for me: I was actually using the fragment programmatically and getting a "caused by":

java.lang.IllegalAccessError: Class ref in pre-verified class resolved to unexpected implementation




回答2:


Solved the problem by adding the following line to the manifest file as a direct element of the application tag this was probably enforced after the new google play services was launched:

<meta-data android:name="com.google.android.gms.version"
   android:value="@integer/google_play_services_version" />

Also a note to fellow developers make sure you extend your activity with FragmentActivity.



来源:https://stackoverflow.com/questions/19977217/map-fragment-not-working-in-android4-4-kitkat

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