填充类片段谷歌API时出错

时间:2014-03-04 14:41:22

标签: java android google-maps android-fragments google-maps-api-2

我在网上搜索了很多,但我不知道我的错误在哪里。我是第一次尝试使用Android API for Maps。 这是我的代码:

public class MapClass extends FragmentActivity
{

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

我的清单:

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

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

<uses-sdk
    android:minSdkVersion="14"
    android:targetSdkVersion="19" />

<uses-permission android:name="it.android.pizzapp.ui.activity.permission.MAP_RECEIVE" />
<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" />
<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/CustomActivityTheme" >

    <meta-data
        android:name="com.google.android.maps.v2.API_KEY"
        android:value="AIzaSyAXB5clxSzUdT8..." />

    <activity
        android:name="it.android.test.activity.MainActivity"
        android:label="@string/app_name" >
        android:theme="@style/CustomActivityTheme"
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />

            <category android:name="android.intent.category.LAUNCHER" />
        </intent-filter>
    </activity>
    <activity
        android:name="it.android.test.activity.MapClass"
        android:label="@string/app_name" >
        android:theme="@style/CustomActivityTheme"
    </activity>
</application>

这是我的MapClass XML:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >

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

</LinearLayout>

这是我的堆栈跟踪:

Failed to inflate
android.view.InflateException: Binary XML file line #8: Error inflating class fragment
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:713)
at android.view.LayoutInflater.rInflate(LayoutInflater.java:755)
at android.view.LayoutInflater.inflate(LayoutInflater.java:492)
at android.view.LayoutInflater.inflate(LayoutInflater.java:397)
at android.view.LayoutInflater.inflate(LayoutInflater.java:353)
at com.android.internal.policy.impl.PhoneWindow.setContentView(PhoneWindow.java:320)
at android.app.Activity.setContentView(Activity.java:1895)
at it.android.test.activity.MapClass.onCreate(InfoResaurantActivity.java:16)
at android.app.Activity.performCreate(Activity.java:5133)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1087)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2293)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2389)
at android.app.ActivityThread.access$600(ActivityThread.java:153)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1269)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:137)
at android.app.ActivityThread.main(ActivityThread.java:5289)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:525)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:739)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:555)
at dalvik.system.NativeStart.main(Native Method)
Caused by: java.lang.IllegalStateException: The meta-data tag in your app's                                                                                      
AndroidManifest.xml does not have the right value.  Expected 4242000 but found 0.
You must have the following declaration within the <application> element:
<meta-data android:name="com.google.android.gms.version"android:value="@integer/google_play_services_version" />

我试图像日志猫所说的那样更改元数据,但错误并没有消失。 有人能帮助我吗?

1 个答案:

答案 0 :(得分:2)

更改此

public class MapClass extends FragmentActivity

public class MapClass extends Activity

这个

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

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

删除

class="com.google.android.gms.maps.SupportMapFragment" 

添加此

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

清单文件中的应用程序内部标记