title: converting android google maps v1 to v2
body: <p>i started to inform me about google maps v2 und so i wanted to get it in my actual app!</p>
  
  <p>in manifest and xml file i did everything (this works) but my problem is in my maps activity! when i click on the button where my app should starts, there only is a black screen and my project crashs :( here the code:</p>
  
  <p>manifest:</p>
  
  <pre><code>   &lt;?xml version="1.0" encoding="utf-8"?&gt;
  &lt;manifest xmlns:android="http://schemas.android.com/apk/res/android"
      package="at.android.kioe"
      android:versionCode="1"
      android:versionName="1.1" 
      &gt;
  
      &lt;uses-sdk android:minSdkVersion="17"
           android:targetSdkVersion="17"/&gt;
  
      &lt;uses-feature
                  android:glEsVersion="0x00020000"
                  android:required="true"/&gt;
      &lt;meta-data
  android:name="com.google.android.maps.v2.API_KEY"
  android:value="my api debug key (v2) " /&gt;
  
      &lt;permission android:name="at.android.kioe.permission.MAPS_RECEIVE" android:protectionLevel="signature"/&gt;
  &lt;uses-permission android:name="at.android.kioe.permission.MAPS_RECEIVE"/&gt;
  &lt;uses-permission android:name="android.permission.INTERNET" /&gt;
  &lt;uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/&gt;
  &lt;uses-permission android:name="com.google.android.providers.gsf.permission.READ_GSERVICES"/&gt;
  &lt;uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" /&gt;
  &lt;uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" /&gt;
  
  
  
      &lt;application
          android:icon="@drawable/label_kulinarik"
          android:label="@string/app_name" &gt;
  
      &lt;uses-library android:name="com.google.android.maps"&gt; &lt;/uses-library&gt;
  
  
   &lt;activity
              android:name=".MainActivity"
              android:label="@string/app_name"
              android:theme="@android:style/Theme.NoTitleBar" &gt;
              &lt;intent-filter&gt;
                  &lt;action android:name="android.intent.action.MAIN" /&gt;
  
                  &lt;category android:name="android.intent.category.LAUNCHER" /&gt;
              &lt;/intent-filter&gt;
          &lt;/activity&gt;
  
   &lt;activity
          android:name=".DataBaseHelper"
             android:theme="@android:style/Theme.NoTitleBar"
               /&gt;
          &lt;activity android:name=".hashmap"
             android:theme="@android:style/Theme.NoTitleBar"
              /&gt;
          &lt;activity android:name=".LocationDemo2"
             android:theme="@android:style/Theme.NoTitleBar"
             /&gt;
  
              /&gt;
          &lt;activity android:name=".Notepadv1"
              android:theme="@android:style/Theme.NoTitleBar"
              /&gt;
     &lt;/application&gt;
  
  &lt;/manifest&gt;
  </code></pre>
  
  <p>main.xml (mapslayout):</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt;
  &lt;RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
      android:layout_width="fill_parent"
      android:layout_height="fill_parent"
      android:gravity="bottom"
      android:orientation="vertical"
      android:padding="6dp" &gt;
  
      &lt;fragment
          android:name="com.google.android.gms.maps.SupportMapFragment"
  
          android:id="@+id/map"
          android:layout_width="fill_parent"
          android:layout_height="fill_parent" /&gt;
  
  
      &lt;FrameLayout
          android:id="@+id/frameLayout2"
          android:layout_width="wrap_content"
          android:layout_height="wrap_content"
          android:layout_above="@+id/frameLayout1"
          android:layout_alignLeft="@+id/frameLayout1"
          android:layout_alignRight="@+id/frameLayout1" &gt;
  
      &lt;/FrameLayout&gt;
  
      &lt;FrameLayout
          android:id="@+id/frameLayout1"
          android:layout_width="wrap_content"
          android:layout_height="wrap_content"
          android:layout_alignParentBottom="true"
          android:layout_alignParentLeft="true" &gt;
  
          &lt;LinearLayout
              android:id="@+id/navi"
              android:layout_width="fill_parent"
              android:layout_height="wrap_content"
              android:gravity="bottom|center" &gt;
  
              &lt;Button
                  android:id="@+id/button1"
                  android:layout_width="80dp"
                  android:layout_height="50dp"
                  android:layout_gravity="center"
                  android:layout_marginTop="3dp"
                  android:background="@color/black"
                  android:drawableTop="@drawable/idee"
                  android:onClick="StartseiteKlick"
                  android:text="Idee"
                  android:textColor="@color/white"
                  android:textSize="5pt" /&gt;
  
              &lt;Button
                  android:id="@+id/button2"
                  android:layout_width="80dp"
                  android:layout_height="50dp"
                  android:layout_gravity="center"
                  android:layout_marginTop="3dp"
                  android:background="@color/black"
                  android:drawableTop="@drawable/betriebe"
                  android:onClick="BezirkeKlick"
                  android:text="Betriebe"
                  android:textColor="@color/white"
                  android:textSize="5pt" /&gt;
  
              &lt;Button
                  android:id="@+id/button3"
                  android:layout_width="80dp"
                  android:layout_height="50dp"
                  android:layout_gravity="center"
                  android:layout_marginTop="3dp"
                  android:background="@color/black"
                  android:drawableTop="@drawable/maps_open"
                  android:onClick="GooglemapsKlick"
                  android:text="Karte"
                  android:textColor="@color/white"
                  android:textSize="5pt" /&gt;
  
              &lt;Button
                  android:id="@+id/button4"
                  android:layout_width="80dp"
                  android:layout_height="50dp"
                  android:layout_gravity="center"
                  android:layout_marginTop="3dp"
                  android:background="@color/black"
                  android:drawableTop="@drawable/suche"
                  android:onClick="SucheKlick"
                  android:text="Suche"
                  android:textColor="@color/white"
                  android:textSize="5pt" /&gt;
          &lt;/LinearLayout&gt;
      &lt;/FrameLayout&gt;
  
  &lt;/RelativeLayout&gt;
  </code></pre>
  
  <p>locationdemo2.java:</p>
  
  <pre><code>    package at.android.kioe;
  
  import android.annotation.SuppressLint;
  import android.app.AlertDialog;
  import android.content.Context;
  import android.content.DialogInterface;
  import android.content.Intent;
  import android.graphics.Bitmap;
  import android.graphics.BitmapFactory;
  import android.graphics.Canvas;
  import android.graphics.Point;
  import android.graphics.drawable.Drawable;
  import android.os.Bundle;
  import android.support.v4.app.FragmentActivity;
  import android.util.Log;
  import android.view.View;
  import android.widget.Toast;
  
  
  import java.util.ArrayList;
  import java.util.List;
  
  import com.google.android.maps.GeoPoint;
  import com.google.android.maps.ItemizedOverlay;
  import com.google.android.maps.MapController;
  import com.google.android.maps.MapView;
  import com.google.android.maps.Overlay;
  import com.google.android.maps.OverlayItem;
  
  @SuppressLint("Override")
  public class LocationDemo2 extends FragmentActivity {
  
    private static final String TAG = "**** "+LocationDemo2.class.getSimpleName();
  
    private MapController mapController;
    MapView mapView;
    GeoPoint geoPoint;
    boolean art;
    int pFeld[];
    int districtID;
    double zielLat,zielLng;  //geographische Breite,Länge als Parameter des Ziels
    private boolean DEBUG = false;
  
  
  
  
  
  
  
    //Buttons:
    public void StartseiteKlick (View vies) {
      setContentView(R.layout.startseite);
      }
    public void GooglemapsKlick (View vies) {
        setContentView(R.layout.googlemaps);
            } 
    public void SucheKlick (View vies) {
          setContentView(R.layout.suche);
      }
    public void BezirkeKlick (View vies) {
          setContentView(R.layout.bezirke);
    }
  
    @Override
    public void onCreate(Bundle savedInstanceState) {
      super.onCreate(savedInstanceState);
      setContentView(R.layout.main);
  
      Intent in = getIntent();
      art = in.getBooleanExtra("karte", false);
      if (art) { //Karte mit allen Betrieben des Bezirks
        districtID=in.getIntExtra("districtID",0);
        pFeld = in.getIntArrayExtra("pFeld"); //Koordinaten der Betriebe
      } else { //Karte mit dem aus der Liste gewählten Betrieb im Mittelpunkt
        zielLat = in.getFloatExtra("lat",0);
        zielLng = in.getFloatExtra("lng",0);
        geoPoint = new GeoPoint((int)(zielLat*1E6), (int)(zielLng*1E6));
      }
      // Zoom aktivieren
  
      // MapController ermitteln
      mapController = mapView.getController();
    } //Ende onCreate
  
    @Override
    protected void onStart() {
      super.onStart();
      if (!art) { //Karte nur für aus der Liste ausgewählten Betrieb
        //fügt der MapView neues Overlay (zum zeichnen der 'current location') hinzu
        List&lt;Overlay&gt; overlays = mapView.getOverlays();
  //    overlays.clear();
        overlays.add(new MyOverlay());
      } else //alle Betriebe in Karte zeichnen
        multipleItems();
    }
  
    private void multipleItems() {
  //      mapView.setSatellite(true);
  
      Drawable markerDefault = this.getResources().getDrawable(R.drawable.mm_20_green);
      MyItemizedOverlay itemizedOverlay = new MyItemizedOverlay(markerDefault);
  
      //für alle Betriebe ein Item aus den Koordinaten bilden und die
      //where-Klausel mit der _id des Betriebes hinzufügen für onTap
      for (int i=0; i&lt;pFeld.length; i+=3) {
        if (pFeld[i+1] &gt; 0)
        itemizedOverlay.addOverlayItem(pFeld[i+1],pFeld[i+2],"_id="+pFeld[i]);
      }
      //alle Items zur MapView hinzufügen
      mapView.getOverlays().add(itemizedOverlay);
      //den Mittelpunkt für den ausgewählten District heraussuchen
      int lat=0,lng=0;
      for (int i=0; i &lt; Notepadv1.mpFeld.length; i+=3) {
        if (Notepadv1.mpFeld[i] == districtID) {
          lat = Notepadv1.mpFeld[i+1];
          lng = Notepadv1.mpFeld[i+2];
          //Darstellung Mittelpunkt
     //       itemizedOverlay.addOverlayItem(lat,lng,"",this.getResources().getDrawable(R.drawable.marker_default));
          mapController.setCenter(new GeoPoint(lat,lng));
          break;
        }
      }
      if (DEBUG) {
        String message="Anzahl Koord.:"+pFeld.length/3+", Mitte:"+lat+","+lng;
        Log.i(TAG,message);
        Toast.makeText(LocationDemo2.this, message, Toast.LENGTH_LONG).show();
      }
      mapController.zoomToSpan(itemizedOverlay.getLatSpanE6(), itemizedOverlay.getLonSpanE6());
    }
  
    @Override
    protected void onDestroy() {
      super.onDestroy();
    }
  
    protected boolean isRouteDisplayed() {
      return false;
    }
  
    /* a private inner class which extends Overlay and override the draw method
     * http://androidcookbook.com/Recipe.seam?recipeId=1541
     * zeichnet als 'overlay' den 'geoPoint' in die Karte
     */
    private class MyOverlay extends com.google.android.maps.Overlay {
      @Override
      public void draw(Canvas canvas, MapView mapView, boolean shadow) {
        super.draw(canvas, mapView, shadow);
        if (!shadow &amp;&amp; geoPoint != null) {
            mapController.setCenter(geoPoint);
            Point point = new Point(); //wird Koordinate des GeoPoint
            mapView.getProjection().toPixels(geoPoint, point);
            Bitmap bmp = BitmapFactory.decodeResource(getResources(),//R.drawable.marker_default);
                    R.drawable.mm_20_green);
            // Shift it left so the center of the image is aligned with the x-coordinate of the geo point
            int x = point.x - bmp.getWidth() / 2;
            // Shift it upward so the bottom of the image is aligned with the y-coordinate of the geo point
            int y = point.y - bmp.getHeight();
            canvas.drawBitmap(bmp, x, y, null);
        }
      }
    }
  
    private class MyItemizedOverlay extends ItemizedOverlay&lt;OverlayItem&gt; {
      private List&lt;OverlayItem&gt; mOverlays = new ArrayList&lt;OverlayItem&gt;();
      public MyItemizedOverlay(Drawable defaultMarker) {
        super(boundCenterBottom(defaultMarker));
      }
      public void addOverlayItem(int lat, int lon, String title, Drawable altMarker) {
        GeoPoint point = new GeoPoint(lat, lon);
        OverlayItem overlayItem = new OverlayItem(point, title, null);
        addOverlayItem(overlayItem, altMarker);
      }
      public void addOverlayItem(int lat, int lon, String title) {
        GeoPoint point = new GeoPoint(lat, lon);
        OverlayItem overlayItem = new OverlayItem(point, title, null);
        addOverlayItem(overlayItem);
      }
      public void addOverlayItem(OverlayItem overlayItem) {
        mOverlays.add(overlayItem);
        populate();
      }
      public void addOverlayItem(OverlayItem overlayItem, Drawable altMarker) {
        overlayItem.setMarker(boundCenterBottom(altMarker));
        addOverlayItem(overlayItem);
      }
      @Override
      protected OverlayItem createItem(int i) {
        return mOverlays.get(i);
      }
      @Override
      public int size() {
        return mOverlays.size();
      }
      @Override
      protected boolean onTap(int index) {
        if (DEBUG)
          Toast.makeText(LocationDemo2.this,
            getItem(index).getTitle()+", Index:"+index, Toast.LENGTH_LONG).show();
        Intent in = new Intent(getApplicationContext(),Notepadv1.class);
        in.putExtra("art", "where");
        //_id des gewählten Listenpunktes
        in.putExtra("where", getItem(index).getTitle());
  
        //Info-Daten zum gewählten Betrieb anzeigen
        String infotext = new hashmap().texte.get(index + 1);
        new AlertDialogManager().showAlertDialog(LocationDemo2.this, "info", infotext, in);
        return true;
  
  
      }
  
  
  
      public class AlertDialogManager 
      {
          public void showAlertDialog(Context context, String title, String infoText, final Intent in) 
          {
              final AlertDialog alertDialog = new AlertDialog.Builder(context).create();
  
              // Setting Dialog Title
              alertDialog.setTitle(title);
  
              // Setting Dialog Message
              alertDialog.setMessage(infoText);
  
              alertDialog.setButton("Info", new DialogInterface.OnClickListener() {
                  public void onClick(DialogInterface dialog, int which) 
                  {
                      startActivity(in);
                  }
              });
  
              alertDialog.setButton2("zurück", new DialogInterface.OnClickListener() {
                  public void onClick(DialogInterface dialog, int which) 
                  {
                      alertDialog.cancel();
                  }
              });
  
              // Showing Alert Message
              alertDialog.show();
          }
      }
  
    }
    public void finish() {}
    public void finishAffinity() {}
  }
  </code></pre>
  
  <p>logcat:</p>
  
  <pre><code>    08-31 17:05:08.981: E/AndroidRuntime(22481): FATAL EXCEPTION: main
  08-31 17:05:08.981: E/AndroidRuntime(22481): java.lang.RuntimeException: Unable to start activity ComponentInfo{at.android.kioe/at.android.kioe.LocationDemo2}: android.view.InflateException: Binary XML file line #9: Error inflating class fragment
  08-31 17:05:08.981: E/AndroidRuntime(22481):    at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2247)
  08-31 17:05:08.981: E/AndroidRuntime(22481):    at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2297)
  08-31 17:05:08.981: E/AndroidRuntime(22481):    at android.app.ActivityThread.access$700(ActivityThread.java:152)
  08-31 17:05:08.981: E/AndroidRuntime(22481):    at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1282)
  08-31 17:05:08.981: E/AndroidRuntime(22481):    at android.os.Handler.dispatchMessage(Handler.java:99)
  08-31 17:05:08.981: E/AndroidRuntime(22481):    at android.os.Looper.loop(Looper.java:137)
  08-31 17:05:08.981: E/AndroidRuntime(22481):    at android.app.ActivityThread.main(ActivityThread.java:5328)
  08-31 17:05:08.981: E/AndroidRuntime(22481):    at java.lang.reflect.Method.invokeNative(Native Method)
  08-31 17:05:08.981: E/AndroidRuntime(22481):    at java.lang.reflect.Method.invoke(Method.java:511)
  08-31 17:05:08.981: E/AndroidRuntime(22481):    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1102)
  08-31 17:05:08.981: E/AndroidRuntime(22481):    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:869)
  08-31 17:05:08.981: E/AndroidRuntime(22481):    at dalvik.system.NativeStart.main(Native Method)
  08-31 17:05:08.981: E/AndroidRuntime(22481): Caused by: android.view.InflateException: Binary XML file line #9: Error inflating class fragment
  08-31 17:05:08.981: E/AndroidRuntime(22481):    at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:710)
  08-31 17:05:08.981: E/AndroidRuntime(22481):    at android.view.LayoutInflater.rInflate(LayoutInflater.java:752)
  08-31 17:05:08.981: E/AndroidRuntime(22481):    at android.view.LayoutInflater.inflate(LayoutInflater.java:495)
  08-31 17:05:08.981: E/AndroidRuntime(22481):    at android.view.LayoutInflater.inflate(LayoutInflater.java:397)
  08-31 17:05:08.981: E/AndroidRuntime(22481):    at android.view.LayoutInflater.inflate(LayoutInflater.java:353)
  08-31 17:05:08.981: E/AndroidRuntime(22481):    at com.android.internal.policy.impl.PhoneWindow.setContentView(PhoneWindow.java:327)
  08-31 17:05:08.981: E/AndroidRuntime(22481):    at android.app.Activity.setContentView(Activity.java:1928)
  08-31 17:05:08.981: E/AndroidRuntime(22481):    at at.android.kioe.LocationDemo2.onCreate(LocationDemo2.java:67)
  08-31 17:05:08.981: E/AndroidRuntime(22481):    at android.app.Activity.performCreate(Activity.java:5250)
  08-31 17:05:08.981: E/AndroidRuntime(22481):    at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1097)
  08-31 17:05:08.981: E/AndroidRuntime(22481):    at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2211)
  08-31 17:05:08.981: E/AndroidRuntime(22481):    ... 11 more
  08-31 17:05:08.981: E/AndroidRuntime(22481): Caused by: java.lang.RuntimeException: API key not found.  Check that &lt;meta-data android:name="com.google.android.maps.v2.API_KEY" android:value="your API key"/&gt; is in the &lt;application&gt; element of AndroidManifest.xml
  08-31 17:05:08.981: E/AndroidRuntime(22481):    at maps.ag.bb.a(Unknown Source)
  08-31 17:05:08.981: E/AndroidRuntime(22481):    at maps.ag.bb.a(Unknown Source)
  08-31 17:05:08.981: E/AndroidRuntime(22481):    at maps.ag.an.a(Unknown Source)
  08-31 17:05:08.981: E/AndroidRuntime(22481):    at maps.ag.bi.a(Unknown Source)
  08-31 17:05:08.981: E/AndroidRuntime(22481):    at maps.ag.bh.a(Unknown Source)
  08-31 17:05:08.981: E/AndroidRuntime(22481):    at blf.onTransact(SourceFile:107)
  08-31 17:05:08.981: E/AndroidRuntime(22481):    at android.os.Binder.transact(Binder.java:310)
  08-31 17:05:08.981: E/AndroidRuntime(22481):    at com.google.android.gms.maps.internal.IMapFragmentDelegate$a$a.onCreateView(Unknown Source)
  08-31 17:05:08.981: E/AndroidRuntime(22481):    at com.google.android.gms.maps.SupportMapFragment$a.onCreateView(Unknown Source)
  08-31 17:05:08.981: E/AndroidRuntime(22481):    at com.google.android.gms.internal.bh$4.b(Unknown Source)
  08-31 17:05:08.981: E/AndroidRuntime(22481):    at com.google.android.gms.internal.bh.a(Unknown Source)
  08-31 17:05:08.981: E/AndroidRuntime(22481):    at com.google.android.gms.internal.bh.onCreateView(Unknown Source)
  08-31 17:05:08.981: E/AndroidRuntime(22481):    at com.google.android.gms.maps.SupportMapFragment.onCreateView(Unknown Source)
  08-31 17:05:08.981: E/AndroidRuntime(22481):    at android.support.v4.app.Fragment.performCreateView(Fragment.java:1478)
  08-31 17:05:08.981: E/AndroidRuntime(22481):    at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:900)
  08-31 17:05:08.981: E/AndroidRuntime(22481):    at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:1082)
  08-31 17:05:08.981: E/AndroidRuntime(22481):    at android.support.v4.app.FragmentManagerImpl.addFragment(FragmentManager.java:1184)
  08-31 17:05:08.981: E/AndroidRuntime(22481):    at android.support.v4.app.FragmentActivity.onCreateView(FragmentActivity.java:285)
  08-31 17:05:08.981: E/AndroidRuntime(22481):    at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:682)
  </code></pre>
  
  <p>i hope that anybody could help me.. i am already searching for hours... </p>