简体   繁体   中英

Google Maps Android API v2

I want to implement Google Maps in my application, so I tried this Google Maps v2

but when I take this code:

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

I get this error:

error: Error: No resource found that matches the given name (at 'value' with value '@integer/ google_play_services_version').

I have

  • imported the google-play-services.jar
  • updated everything in the SDK Manager

after all it still doesn't work, I imported libproject\\google-play-services_lib\\res\\values\\version.xml to my project

this error is away but if I run the project on my device the logcat shows this error message

12-28 17:22:29.850: E/AndroidRuntime(28040): FATAL EXCEPTION: main 12-28 17:22:29.850: E/AndroidRuntime(28040): java.lang.RuntimeException: Unable to start activity ComponentInfo{#############.MainActivity}: android.view.InflateException: Binary XML file line #2: Error inflating class fragment 12-28 17:22:29.850: E/AndroidRuntime(28040): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1968) 12-28 17:22:29.850: E/AndroidRuntime(28040): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1993) 12-28 17:22:29.850: E/AndroidRuntime(28040): at android.app.ActivityThread.access$600(ActivityThread.java:127) 12-28 17:22:29.850: E/AndroidRuntime(28040): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1151) 12-28 17:22:29.850: E/AndroidRuntime(28040): at android.os.Handler.dispatchMessage(Handler.java:99) 12-28 17:22:29.850: E/AndroidRuntime(28040): at android.os.Looper.loop(Looper.java:137) 12-28 17:22:29.850: E/AndroidRuntime(28040): at android.app.ActivityThread.main(ActivityThread.java:4499) 12-28 17:22:29.850: E/AndroidRuntime(28040): at java.lang.reflect.Method.invokeNative(Native Method) 12-28 17:22:29.850: E/AndroidRuntime(28040): at java.lang.reflect.Method.invoke(Method.java:511) 12-28 17:22:29.850: E/AndroidRuntime(28040): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:788) 12-28 17:22:29.850: E/AndroidRuntime(28040): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:555) 12-28 17:22:29.850: E/AndroidRuntime(28040): at dalvik.system.NativeStart.main(Native Method) 12-28 17:22:29.850: E/AndroidRuntime(28040): Caused by: android.view.InflateException: Binary XML file line #2: Error inflating class fragment 12-28 17:22:29.850: E/AndroidRuntime(28040): at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:697) 12-28 17:22:29.850: E/AndroidRuntime(28040): at android.view.LayoutInflater.inflate(LayoutInflater.java:466) 12-28 17:22:29.850: E/AndroidRuntime(2 8040): at android.view.LayoutInflater.inflate(LayoutInflater.java:396) 12-28 17:22:29.850: E/AndroidRuntime(28040): at android.view.LayoutInflater.inflate(LayoutInflater.java:352) 12-28 17:22:29.850: E/AndroidRuntime(28040): at com.android.internal.policy.impl.PhoneWindow.setContentView(PhoneWindow.java:267) 12-28 17:22:29.850: E/AndroidRuntime(28040): at android.app.Activity.setContentView(Activity.java:2007) 12-28 17:22:29.850: E/AndroidRuntime(28040): at #########.MainActivity.onCreate(MainActivity.java:11) 12-28 17:22:29.850: E/AndroidRuntime(28040): at android.app.Activity.performCreate(Activity.java:4637) 12-28 17:22:29.850: E/AndroidRuntime(28040): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1051) 12-28 17:22:29.850: E/AndroidRuntime(28040): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1932) 12-28 17:22:29.850: E/AndroidRuntime(28040): ... 11 more 12-28 17:22:29.850: E/AndroidRuntime(28040): Caused by: android.app.Fragment$ InstantiationException: Unable to instantiate fragment com.google.android.gms.maps.MapFragment: make sure class name exists, is public, and has an empty constructor that is public 12-28 17:22:29.850: E/AndroidRuntime(28040): at android.app.Fragment.instantiate(Fragment.java:581) 12-28 17:22:29.850: E/AndroidRuntime(28040): at android.app.Fragment.instantiate(Fragment.java:549) 12-28 17:22:29.850: E/AndroidRuntime(28040): at android.app.Activity.onCreateView(Activity.java:4407) 12-28 17:22:29.850: E/AndroidRuntime(28040): at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:673) 12-28 17:22:29.850: E/AndroidRuntime(28040): ... 20 more 12-28 17:22:29.850: E/AndroidRuntime(28040): Caused by: java.lang.ClassNotFoundException: com.google.android.gms.maps.MapFragment 12-28 17:22:29.850: E/AndroidRuntime(28040): at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:61) 12-28 17:22:29.850: E/AndroidRuntime(28040): at java.lang.ClassLoader.loadClass(ClassLoader.j ava:501) 12-28 17:22:29.850: E/AndroidRuntime(28040): at java.lang.ClassLoader.loadClass(ClassLoader.java:461) 12-28 17:22:29.850: E/AndroidRuntime(28040): at android.app.Fragment.instantiate(Fragment.java:571) 12-28 17:22:29.850: E/AndroidRuntime(28040): ... 23 more

I have my own API Key and the name of the package is correct. Maybe there is some problem with my eclipse or the android sdk!?

How have you imported it? You have to add google-play-services as a library to your project.

After importing the google-play-services project, you have to add this library project to your application like this-

right click the project --> properties --> Android --> Add --> select google-play-services --> Ok --> Apply --> Ok

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