2013-01-20 10 views
5

Ich befolge Schritte zur Konfiguration von Google Maps Android API v2 Official steps
Ich benutze Android 3.1 Version. Ich bekomme Fehler, die ich Projekt ausführen.
Manifest-DateiAndroid: Google Karte api Version 2

<?xml version="1.0" encoding="utf-8"?> 
<manifest xmlns:android="http://schemas.android.com/apk/res/android" 
    package="com.example.mapdemo" 
    android:versionCode="1" 
    android:versionName="1.0" > 

    <uses-sdk 
     android:minSdkVersion="8" 
     android:targetSdkVersion="17" /> 

    <uses-feature 
     android:glEsVersion="0x00020000" 
     android:required="true"/> 

    <permission 
      android:name="com.example.mapdemo.permission.MAPS_RECEIVE" 
      android:protectionLevel="signature"/> 
     <uses-permission android:name="com.example.mapdemo.permission.MAPS_RECEIVE"/> 
     <uses-permission android:name="android.permission.INTERNET"/> 
     <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/> 
     <uses-permission android:name="com.google.android.providers.gsf.permission.READ_GSERVICES"/> 
     <uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION"/> 
     <uses-permission android:name="android.permission.ACCESS_FINE_LOCATION"/> 


    <application 
     android:allowBackup="true" 
     android:icon="@drawable/ic_launcher" 
     android:label="@string/app_name" 
     android:theme="@style/AppTheme" > 
     <activity 
      android:name="com.example.mapdemo.MainActivity" 
      android:label="@string/app_name" > 
      <intent-filter> 
       <action android:name="android.intent.action.MAIN" /> 

       <category android:name="android.intent.category.LAUNCHER" /> 
      </intent-filter> 
     </activity> 
     <meta-data 
      android:name="com.google.android.maps.v2.API_KEY" 
      android:value="I paste my key as shown in picture"/>   
    </application> 

</manifest> 

Api Key MainActivity.java

package com.example.mapdemo; 
import android.os.Bundle; 
import android.app.Activity; 
import android.view.Menu; 

public class MainActivity extends Activity { 

    @Override 
    protected void onCreate(Bundle savedInstanceState) { 
     super.onCreate(savedInstanceState); 
     setContentView(R.layout.activity_main); 
    } 

    @Override 
    public boolean onCreateOptionsMenu(Menu menu) { 
     // Inflate the menu; this adds items to the action bar if it is present. 
     getMenuInflater().inflate(R.menu.activity_main, menu); 
     return true; 
    } 
} 

Activity_main.xml

<?xml version="1.0" encoding="utf-8"?> 
<fragment xmlns:android="http://schemas.android.com/apk/res/android" 
    android:id="@+id/map" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    class="com.google.android.gms.maps.MapFragment"/> 

LogCat

01-20 15:00:18.325: E/dalvikvm(856): Could not find class 'com.google.android.gms.maps.model.LatLng', referenced from method com.google_map.MainActivity.<clinit> 
01-20 15:00:18.395: E/dalvikvm(856): Could not find class 'com.google.android.gms.maps.MapFragment', referenced from method com.google_map.MainActivity.onCreate 
01-20 15:00:18.565: E/AndroidRuntime(856): FATAL EXCEPTION: main 
01-20 15:00:18.565: E/AndroidRuntime(856): java.lang.ExceptionInInitializerError 
01-20 15:00:18.565: E/AndroidRuntime(856): at java.lang.Class.newInstanceImpl(Native Method) 
01-20 15:00:18.565: E/AndroidRuntime(856): at java.lang.Class.newInstance(Class.java:1301) 
01-20 15:00:18.565: E/AndroidRuntime(856): at android.app.Instrumentation.newActivity(Instrumentation.java:1022) 
01-20 15:00:18.565: E/AndroidRuntime(856): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1663) 
01-20 15:00:18.565: E/AndroidRuntime(856): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1764) 
01-20 15:00:18.565: E/AndroidRuntime(856): at android.app.ActivityThread.access$1500(ActivityThread.java:122) 
01-20 15:00:18.565: E/AndroidRuntime(856): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1002) 
01-20 15:00:18.565: E/AndroidRuntime(856): at android.os.Handler.dispatchMessage(Handler.java:99) 
01-20 15:00:18.565: E/AndroidRuntime(856): at android.os.Looper.loop(Looper.java:132) 
01-20 15:00:18.565: E/AndroidRuntime(856): at android.app.ActivityThread.main(ActivityThread.java:4025) 
01-20 15:00:18.565: E/AndroidRuntime(856): at java.lang.reflect.Method.invokeNative(Native Method) 
01-20 15:00:18.565: E/AndroidRuntime(856): at java.lang.reflect.Method.invoke(Method.java:491) 
01-20 15:00:18.565: E/AndroidRuntime(856): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:841) 
01-20 15:00:18.565: E/AndroidRuntime(856): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:599) 
01-20 15:00:18.565: E/AndroidRuntime(856): at dalvik.system.NativeStart.main(Native Method) 
01-20 15:00:18.565: E/AndroidRuntime(856): Caused by: java.lang.NoClassDefFoundError: com.google.android.gms.maps.model.LatLng 
01-20 15:00:18.565: E/AndroidRuntime(856): at com.google_map.MainActivity.<clinit>(MainActivity.java:32) 
01-20 15:00:18.565: E/AndroidRuntime(856): ... 15 more 

Ich möchte auch Mindestanforderung für Google map API v2 wissen

+1

Haben Sie das SDK für Google Play-Dienste installiert und es als Bibliothek hinzugefügt? –

Antwort

1

Zuerst installieren Sie Google Play-Dienst versuchen, und wenn Sie mit Android 2.2 verwenden Sie dann diesen Code

public class MainActivity extends FragmentActivity {  
    @Override 
    protected void onCreate(Bundle savedInstanceState) { 
     super.onCreate(savedInstanceState);  
     SupportMapFragment fragment = new SupportMapFragment(); 
     getSupportFragmentManager().beginTransaction().add(android.R.id.content, fragment).commit(); 
    }  
    @Override 
    public boolean onCreateOptionsMenu(Menu menu) { 
     // Inflate the menu; this adds items to the action bar if it is present. 
     getMenuInflater().inflate(R.menu.activity_main, menu); 
     return true; 
    } 
} 
0

Ich sah ein ähnliches Problem und löste dieses Problem mit den folgenden Szenarioschritten:

-1- Ich habe die neueste ADT (die Windows 64 Bit Version 23.0.3) heruntergeladen, um die Google Play Services API zu installieren.

-2- Das Problem bestand immer noch, versuchte @ user3469294 Antwort in diesem link.

Es ist etwas falsch mit ADT 64-Bit-Version, wenn es darum geht, den SupportMapFragment zu verwenden (stürzt immer wieder ab), ADT für 32-Bit-Downloads und die Installation von Google-Play-Services-API auf seine SDK dann mein Problem gelöst, es ist Bibliothek.