map v2 api错误膨胀类片段

时间:2014-10-13 09:38:40

标签: android android-fragments

我有以下代码

layout.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"
  android:name="com.google.android.gms.maps.SupportMapFragment" />

HomePage.java

import com.google.android.gms.maps.GoogleMap;
import com.google.android.gms.maps.SupportMapFragment;
import com.google.android.gms.maps.model.LatLng;
import com.google.android.gms.maps.model.MarkerOptions;

import android.os.Bundle;
import android.support.v4.app.FragmentActivity;


public class HomePage extends FragmentActivity{

@Override
protected void onCreate(Bundle savedInstanceState) {
    // TODO Auto-generated method stub
    super.onCreate(savedInstanceState);
    setContentView(R.layout.home);

    GoogleMap map = 
            ((SupportMapFragment)getSupportFragmentManager()
            .findFragmentById(R.id.map)).getMap();
map.addMarker(new MarkerOptions().position(new
            LatLng(34.739849,-92.307129)).title("SwagString"));


}
}

的manifest.xml

<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="gr.websector.servicescheduler"
android:versionCode="1"
android:versionName="1.0" >

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


<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" />


<application
    android:icon="@drawable/ic_launcher"
    android:label="@string/app_name"
    android:theme="@style/AppTheme" >
    <meta-data 
        android:name="com.google.android.maps.v2.API_KEY"
        android:value="MY_API_KEY_HERE" />

    <activity
        android:name=".MainActivity"
        android:label="@string/title_activity_main" 
        android:screenOrientation="landscape" >
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />
            <category android:name="android.intent.category.LAUNCHER" />
        </intent-filter>
    </activity>
    <activity
        android:name=".LoginActivity"
        android:label="@string/title_activity_main"
        android:screenOrientation="landscape"  >
        <intent-filter>
            <action android:name="gr.websector.serviceschedule.LOGIN" />
            <category android:name="android.intent.category.DEFAULT" />
        </intent-filter>
    </activity>
    <activity
        android:name=".HomePage"
        android:label="@string/title_activity_main"
        android:screenOrientation="landscape" >
        <intent-filter>
            <action android:name="gr.websector.serviceschedule.HOME" />
            <category android:name="android.intent.category.DEFAULT" />
        </intent-filter>
    </activity>
</application>

每当我调试我的应用程序时,我收到错误“错误膨胀类片段”。你能帮帮我吗? 我也正在调试我的应用程序在三星p5100。

提前致谢。

1 个答案:

答案 0 :(得分:1)

您应该在<meta-data>

<application>标记下添加Google Play服务版本manifest.xml标记
  <meta-data
        android:name="com.google.android.gms.version"
        android:value="@integer/google_play_services_version" />

也是你的android:minSdkVersion="12",所以你应该改变这个

android:name="com.google.android.gms.maps.SupportMapFragment"

android:name="com.google.android.gms.maps.MapFragment"

并且也改变了这个

public class HomePage extends FragmentActivity{

public class HomePage extends Activity{