问题
I am trying to open google maps to show some locations. I am following http://mobisys.in/blog/2012/12/google-rolls-out-android-maps-api-v2/ link for this, but its not opening maps its crashing and says inflate exception binary file number #2, i have checked in manifest meta data is fine, fragment is case sensitive, key is correct , here it is my stack trace :
02-26 18:15:25.648: I/System.out(5029): img button cust.>> 02-26
18:15:25.718: D/AndroidRuntime(5029): Shutting down VM 02-26
18:15:25.718: W/dalvikvm(5029): threadid=1: thread exiting with
uncaught exception (group=0x40a191f8) 02-26 18:15:25.758:
E/AndroidRuntime(5029): FATAL EXCEPTION: main 02-26 18:15:25.758:
E/AndroidRuntime(5029): java.lang.RuntimeException: Unable to start
activity
ComponentInfo{com.intertec.iforce/com.intertec.iforce.MapActivity}:
android.view.InflateException: Binary XML file line #2: Error
inflating class fragment 02-26 18:15:25.758: E/AndroidRuntime(5029):
at
android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1956)
02-26 18:15:25.758: E/AndroidRuntime(5029): at
android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1981)
02-26 18:15:25.758: E/AndroidRuntime(5029): at
android.app.ActivityThread.access$600(ActivityThread.java:123) 02-26
18:15:25.758: E/AndroidRuntime(5029): at
android.app.ActivityThread$H.handleMessage(ActivityThread.java:1147)
02-26 18:15:25.758: E/AndroidRuntime(5029): at
android.os.Handler.dispatchMessage(Handler.java:99) 02-26
18:15:25.758: E/AndroidRuntime(5029): at
android.os.Looper.loop(Looper.java:137) 02-26 18:15:25.758:
E/AndroidRuntime(5029): at
android.app.ActivityThread.main(ActivityThread.java:4424) 02-26
18:15:25.758: E/AndroidRuntime(5029): at
java.lang.reflect.Method.invokeNative(Native Method) 02-26
18:15:25.758: E/AndroidRuntime(5029): at
java.lang.reflect.Method.invoke(Method.java:511) 02-26 18:15:25.758:
E/AndroidRuntime(5029): at
com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:784)
02-26 18:15:25.758: E/AndroidRuntime(5029): at
com.android.internal.os.ZygoteInit.main(ZygoteInit.java:551) 02-26
18:15:25.758: E/AndroidRuntime(5029): at
dalvik.system.NativeStart.main(Native Method) 02-26 18:15:25.758:
E/AndroidRuntime(5029): Caused by: android.view.InflateException:
Binary XML file line #2: Error inflating class fragment 02-26
18:15:25.758: E/AndroidRuntime(5029): at
android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:697)
02-26 18:15:25.758: E/AndroidRuntime(5029): at
android.view.LayoutInflater.inflate(LayoutInflater.java:466) 02-26
18:15:25.758: E/AndroidRuntime(5029): at
android.view.LayoutInflater.inflate(LayoutInflater.java:396) 02-26
18:15:25.758: E/AndroidRuntime(5029): at
android.view.LayoutInflater.inflate(LayoutInflater.java:352) 02-26
18:15:25.758: E/AndroidRuntime(5029): at
com.android.internal.policy.impl.PhoneWindow.setContentView(PhoneWindow.java:251)
02-26 18:15:25.758: E/AndroidRuntime(5029): at
android.app.Activity.setContentView(Activity.java:1862) 02-26
18:15:25.758: E/AndroidRuntime(5029): at
com.intertec.iforce.MapActivity.onCreate(MapActivity.java:23) 02-26
18:15:25.758: E/AndroidRuntime(5029): at
android.app.Activity.performCreate(Activity.java:4492) 02-26
18:15:25.758: E/AndroidRuntime(5029): at
android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1049)
02-26 18:15:25.758: E/AndroidRuntime(5029): at
android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1920)
02-26 18:15:25.758: E/AndroidRuntime(5029): ... 11 more 02-26
18:15:25.758: E/AndroidRuntime(5029): Caused by:
android.support.v4.app.Fragment$InstantiationException: Unable to
instantiate fragment com.google.android.gms.maps.SupportMapFragment:
make sure class name exists, is public, and has an empty constructor
that is public 02-26 18:15:25.758: E/AndroidRuntime(5029): at
android.support.v4.app.Fragment.instantiate(Fragment.java:401) 02-26
18:15:25.758: E/AndroidRuntime(5029): at
android.support.v4.app.Fragment.instantiate(Fragment.java:369) 02-26
18:15:25.758: E/AndroidRuntime(5029): at
android.support.v4.app.FragmentActivity.onCreateView(FragmentActivity.java:272)
02-26 18:15:25.758: E/AndroidRuntime(5029): at
android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:669)
02-26 18:15:25.758: E/AndroidRuntime(5029): ... 20 more 02-26
18:15:25.758: E/AndroidRuntime(5029): Caused by:
java.lang.ClassNotFoundException:
com.google.android.gms.maps.SupportMapFragment 02-26 18:15:25.758:
E/AndroidRuntime(5029): at
dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:61)
02-26 18:15:25.758: E/AndroidRuntime(5029): at
java.lang.ClassLoader.loadClass(ClassLoader.java:501) 02-26
18:15:25.758: E/AndroidRuntime(5029): at
java.lang.ClassLoader.loadClass(ClassLoader.java:461) 02-26
18:15:25.758: E/AndroidRuntime(5029): at
android.support.v4.app.Fragment.instantiate(Fragment.java:391) 02-26
18:15:25.758: E/AndroidRuntime(5029): ... 23 more 02-26 18:15:25.838:
D/dalvikvm(5029): GC_CONCURRENT freed 326K, 20% free 6795K/8391K,
paused 2ms+2ms 02-26 18:20:25.808: I/Process(5029): Sending signal.
PID: 5029 SIG: 9
回答1:
It looks you have missed to import the project from \extras\google\google_play_services\libproject\google-play-services_lib
.
Add it as library
to your current project.
Make sure you have used SupportMapFragment
for API under 11.
?xml version="1.0" encoding="utf-8"?>
<fragment xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/map"
android:name="com.google.android.gms.maps.SupportMapFragment"
android:layout_width="wrap_content"
android:layout_height="match_parent" />
来源:https://stackoverflow.com/questions/15089590/show-google-maps-in-android-v2-app-crashes-on-open-activity-inflate-exception-b