0

这是我的项目代码,但是当我运行它时,它会立即关闭

这是我的MainActivity类包 com.example.freearmymaps;

import android.os.Bundle;
import android.app.Activity;
import android.view.Menu;
import com.google.android.gms.common.GooglePlayServicesUtil;
import com.google.android.gms.maps.GoogleMap;
import com.google.android.gms.maps.MapFragment;
import com.google.android.gms.maps.model.BitmapDescriptorFactory;
import com.google.android.gms.maps.model.LatLng;
import com.google.android.gms.maps.model.Marker;
import com.google.android.gms.maps.model.MarkerOptions;
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

    <fragment xmlns:android="http://schemas.android.com/apk/res/android"
          android:id="@+id/map"
          android:layout_width="match_parent"
          android:layout_height="match_parent"
          android:name="com.google.android.gms.maps.MapFragment"/>
</RelativeLayout>

这是AndroidManifest

    <uses-sdk
        android:minSdkVersion="8"
        android:targetSdkVersion="16" />
    <uses-feature
        android:glEsVersion="0x00020000"
        android:required="true"/>
<uses-permission android:name="android.permission.INTERNET"/>
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
<uses-permission android:name="com.google.android.providers.gsf.permission.READ_GSERVICES"/>
<!-- The following two permissions are not required to use
     Google Maps Android API v2, but are recommended. -->
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION"/>
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION"/>
<uses-permission android:name="com.example.freearmymaps.MAPS_RECEIVE"/>    
    <permission 
        android:name="com.example.freearmymaps.MAPS_RECEIVE"
        android:protectionLevel="signature"/>
    <application
        android:allowBackup="true"
        android:icon="@drawable/ic_launcher"
        android:label="@string/app_name"
        android:theme="@style/AppTheme" >
      <!--   <activity android:name="com.example.freearmymaps.library.googleplayserviceslib" /> -->
        <activity
            android:name="com.example.freearmymaps.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="AIzaSyDWPLxsxJb-hzckZf50czZ8pnuub3a-Hjo"/>
    </application>


</manifest>

请问谁能告诉我问题出在哪里,我该如何解决?

4

1 回答 1

0

你的最小 SDK 是 8。

如果您的目标是 API 12 及更高版本,请使用MapFragment. 否则,使用SupportMapFragment.

<fragment
class="com.google.android.gms.maps.SupportMapFragment"
android:id="@+id/map"  
android:layout_width="match_parent"
android:layout_height="match_parent"/>

您的活动必须延长FragmentActivity

SupportMapFragment fm = (SupportMapFragment)  getSupportFragmentManager().findFragmentById(R.id.map);
GoogleMap mMap = fm.getMap(); 

确保您已添加支持库

还要确保您导入了以下内容

import android.support.v4.app.FragmentActivity;  
import com.google.android.gms.maps.SupportMapFragment;    
于 2013-06-20T08:59:24.453 回答