Android Google Maps API“填充类片段错误”

时间:2014-01-10 08:38:50

标签: android google-maps android-fragments android-fragmentactivity

  

我是Android开发人员的新手,我从一些简单的事情开始,只是以我居住的地方为中心显示地图。我一直在尝试很多东西来解决我的问题,没有任何成功,我会留下我的代码和错误日志。如果你能帮助我,我将非常感激;]

错误地膨胀类片段:

01-10 03:04:51.632: E/AndroidRuntime(1366): FATAL EXCEPTION: main
01-10 03:04:51.632: E/AndroidRuntime(1366): java.lang.RuntimeException: Unable to start activity ComponentInfo{br.com.lineapp.tofind/br.com.lineapp.tofind.MapActivity}: android.view.InflateException: Binary XML file line #13: Error inflating class fragment
01-10 03:04:51.632: E/AndroidRuntime(1366):     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2211)
01-10 03:04:51.632: E/AndroidRuntime(1366):     at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2261)
01-10 03:04:51.632: E/AndroidRuntime(1366):     at android.app.ActivityThread.access$600(ActivityThread.java:141)
01-10 03:04:51.632: E/AndroidRuntime(1366):     at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1256)
01-10 03:04:51.632: E/AndroidRuntime(1366):     at android.os.Handler.dispatchMessage(Handler.java:99)
01-10 03:04:51.632: E/AndroidRuntime(1366):     at android.os.Looper.loop(Looper.java:137)
01-10 03:04:51.632: E/AndroidRuntime(1366):     at android.app.ActivityThread.main(ActivityThread.java:5103)
01-10 03:04:51.632: E/AndroidRuntime(1366):     at java.lang.reflect.Method.invokeNative(Native Method)
01-10 03:04:51.632: E/AndroidRuntime(1366):     at java.lang.reflect.Method.invoke(Method.java:525)
01-10 03:04:51.632: E/AndroidRuntime(1366):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:737)
01-10 03:04:51.632: E/AndroidRuntime(1366):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:553)
01-10 03:04:51.632: E/AndroidRuntime(1366):     at dalvik.system.NativeStart.main(Native Method)
01-10 03:04:51.632: E/AndroidRuntime(1366): Caused by: android.view.InflateException: Binary XML file line #13: Error inflating class fragment
01-10 03:04:51.632: E/AndroidRuntime(1366):     at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:713)
01-10 03:04:51.632: E/AndroidRuntime(1366):     at android.view.LayoutInflater.rInflate(LayoutInflater.java:755)
01-10 03:04:51.632: E/AndroidRuntime(1366):     at android.view.LayoutInflater.inflate(LayoutInflater.java:492)
01-10 03:04:51.632: E/AndroidRuntime(1366):     at android.view.LayoutInflater.inflate(LayoutInflater.java:397)
01-10 03:04:51.632: E/AndroidRuntime(1366):     at android.view.LayoutInflater.inflate(LayoutInflater.java:353)
01-10 03:04:51.632: E/AndroidRuntime(1366):     at com.android.internal.policy.impl.PhoneWindow.setContentView(PhoneWindow.java:267)
01-10 03:04:51.632: E/AndroidRuntime(1366):     at android.app.Activity.setContentView(Activity.java:1895)
01-10 03:04:51.632: E/AndroidRuntime(1366):     at br.com.lineapp.tofind.MapActivity.onCreate(MapActivity.java:14)
01-10 03:04:51.632: E/AndroidRuntime(1366):     at android.app.Activity.performCreate(Activity.java:5133)
01-10 03:04:51.632: E/AndroidRuntime(1366):     at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1087)
01-10 03:04:51.632: E/AndroidRuntime(1366):     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2175)
01-10 03:04:51.632: E/AndroidRuntime(1366):     ... 11 more
01-10 03:04:51.632: E/AndroidRuntime(1366): Caused by: java.lang.IllegalStateException: The meta-data tag in your app's AndroidManifest.xml does not have the right value.  Expected 4030500 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" />
01-10 03:04:51.632: E/AndroidRuntime(1366):     at com.google.android.gms.common.GooglePlayServicesUtil.n(Unknown Source)
01-10 03:04:51.632: E/AndroidRuntime(1366):     at com.google.android.gms.common.GooglePlayServicesUtil.isGooglePlayServicesAvailable(Unknown Source)
01-10 03:04:51.632: E/AndroidRuntime(1366):     at com.google.android.gms.maps.internal.q.v(Unknown Source)
01-10 03:04:51.632: E/AndroidRuntime(1366):     at com.google.android.gms.maps.internal.q.u(Unknown Source)
01-10 03:04:51.632: E/AndroidRuntime(1366):     at com.google.android.gms.maps.MapsInitializer.initialize(Unknown Source)
01-10 03:04:51.632: E/AndroidRuntime(1366):     at com.google.android.gms.maps.MapFragment$b.cE(Unknown Source)
01-10 03:04:51.632: E/AndroidRuntime(1366):     at com.google.android.gms.maps.MapFragment$b.a(Unknown Source)
01-10 03:04:51.632: E/AndroidRuntime(1366):     at com.google.android.gms.dynamic.a.a(Unknown Source)
01-10 03:04:51.632: E/AndroidRuntime(1366):     at com.google.android.gms.dynamic.a.onInflate(Unknown Source)
01-10 03:04:51.632: E/AndroidRuntime(1366):     at com.google.android.gms.maps.MapFragment.onInflate(Unknown Source)
01-10 03:04:51.632: E/AndroidRuntime(1366):     at android.app.Activity.onCreateView(Activity.java:4745)
01-10 03:04:51.632: E/AndroidRuntime(1366):     at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:689)
01-10 03:04:51.632: E/AndroidRuntime(1366):     ... 21 more

MainActivity:

package br.com.lineapp.tofind;

import android.os.Bundle;
import android.app.Activity;
import android.content.Intent;
//import android.view.Menu;
import android.view.View;

public class MainActivity extends Activity {

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

public void verMapa(View v){
    Intent iVerMapa = new Intent(MainActivity.this,MapActivity.class);
        startActivity(iVerMapa);
    }

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

}

MapActivity:

package br.com.lineapp.tofind;

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



public class MapActivity extends FragmentActivity {
@Override

protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.map_2find);
}

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

布局 - acitivity_main:

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/layoutMain"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#EEE9E9"
 >

<LinearLayout
    android:id="@+id/layoutPrincial"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical"
    android:layout_marginLeft="50dp"
    android:layout_marginRight="50dp">

    <ImageView
        android:id="@+id/mapaLayout"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_weight="2"
        android:src="@drawable/mapa"
        android:layout_marginBottom="20dp" />

    <LinearLayout
        android:id="@+id/layoutBotoes"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:orientation="vertical"
        android:layout_weight="1"
        android:layout_marginBottom="20dp">

        <Button
            android:id="@+id/button1"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_weight="1"
            android:text="@string/map"
            android:background="#00FF7F"
            android:layout_marginBottom="10dp"
            android:onClick="verMapa" />

        <Button
            android:id="@+id/button2"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_weight="1"
            android:text="@string/contatos"
            android:background="#00FF7F"
            android:layout_marginBottom="10dp" />

        <Button
            android:id="@+id/button3"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_weight="1"
            android:text="@string/sair"
            android:background="#00FF7F"
            android:layout_marginBottom="10dp" />
    </LinearLayout>
</LinearLayout>



</RelativeLayout>

布局 - map_2find:

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/layoutMap"
android:layout_width="match_parent"
android:layout_height="match_parent"

 >
 <TextView
    android:id="@+id/mano"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:text="@string/hello_world" />

<fragment
      android:id="@+id/map"
      android:layout_width="match_parent"
      android:layout_height="match_parent"
      android:layout_below="@+id/mano"
      android:name="com.google.android.gms.maps.MapFragment"
/>

</RelativeLayout>

AndroidManifest

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

<permission
    android:name="br.com.lineapp.tofind.permission.MAPS_RECEIVE"
    android:protectionLevel="signature"/>

<uses-permission  android:name="br.com.lineapp.tofind.permission.MAPS_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"/>

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

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

<application
    android:allowBackup="true"
    android:icon="@drawable/ic_launcher"
    android:label="@string/app_name"
    android:theme="@style/AppTheme" >

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

    <activity
        android:name="br.com.lineapp.tofind.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>

    <activity
        android:name="br.com.lineapp.tofind.MapActivity"
        android:label="@string/app_name" >
    </activity>

</application>

</manifest>

1 个答案:

答案 0 :(得分:0)

检查

A required meta-data tag in your app's AndroidManifest.xml does not exist.

除此之外

<uses-sdk
    android:minSdkVersion="8"

所以改变

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

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

同时删除此

<permission
android:name="br.com.lineapp.tofind.permission.MAPS_RECEIVE"
android:protectionLevel="signature"/>

和这个

<uses-permission  android:name="br.com.lineapp.tofind.permission.MAPS_RECEIVE"/>

不需要

参考:

https://developers.google.com/maps/documentation/android/start