本文介绍了Android Google Maps API和“错误夸大类片段"的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

膨胀类片段的错误:

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:

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:

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:

Layout - 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_2查找:

layout - 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

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>

推荐答案

选中此

您应用的AndroidManifest.xml中的必需元数据标记不存在.

除此之外

<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

这篇关于Android Google Maps API和“错误夸大类片段"的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-14 13:37