Android 谷歌地图错误,无法启动 Activity ComponentInfo

标签 android google-maps

我在谷歌地图上试过一个小例子。我有 API key ,但是当我运行项目时,它显示以下错误。我还导入了 Google Play 服务。

我的 XML 文件

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

    <fragment
        android:id="@+id/map"

        android:name="com.google.android.gms.maps.SupportMapFragment"
        android:layout_width="match_parent"
        android:layout_height="match_parent"/>

</RelativeLayout>

我的Java

package com.arun.maps;

import com.google.android.gms.maps.GoogleMap;
import com.google.android.gms.maps.SupportMapFragment;

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

public class GoogleMapS extends FragmentActivity {
    private GoogleMap googleMap;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.google_map);
        try {
            // Loading map
            initilizeMap();  

        } catch (Exception e) {   
            e.printStackTrace();
        }     

    }
    private void initilizeMap() {    
        if (googleMap == null) {
            googleMap = ((SupportMapFragment) getSupportFragmentManager().findFragmentById(   
                    R.id.map)).getMap();

            // check if map is created successfully or not
            if (googleMap == null) {   
                Toast.makeText(getApplicationContext(),
                        "Sorry! unable to create maps", Toast.LENGTH_SHORT)  
                        .show();
            }
        }
    }
    @Override    
    protected void onResume() {   
        super.onResume();   
        initilizeMap(); 
    }

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

}

Android list

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

    <uses-sdk
        android:minSdkVersion="10"
        android:targetSdkVersion="10" />
    <uses-permission android:name="android.permission.INTERNET" />


    <!-- Required OpenGL ES 2.0. for Maps V2 -->
    <uses-feature
        android:glEsVersion="0x00020000"    
        android:required="true" />
    <application
        android:allowBackup="true"
        android:icon="@drawable/ic_launcher"
        android:label="@string/app_name"
        android:theme="@style/AppTheme" >
        <uses-library android:name="com.google.android.maps" />
        <activity
            android:name="com.arun.maps.GoogleMapS"
            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="
AIzaSyBn3b2eGABl1JL-xXKe1H_uf4UtPRUUAwY" />
    </application>


</manifest>

错误:

04-02 17:21:39.355: E/AndroidRuntime(719): FATAL EXCEPTION: main
04-02 17:21:39.355: E/AndroidRuntime(719): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.arun.maps/com.arun.maps.GoogleMapS}: android.view.InflateException: Binary XML file line #6: Error inflating class fragment
04-02 17:21:39.355: E/AndroidRuntime(719):  at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1647)
04-02 17:21:39.355: E/AndroidRuntime(719):  at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1663)
04-02 17:21:39.355: E/AndroidRuntime(719):  at android.app.ActivityThread.access$1500(ActivityThread.java:117)
04-02 17:21:39.355: E/AndroidRuntime(719):  at android.app.ActivityThread$H.handleMessage(ActivityThread.java:931)
04-02 17:21:39.355: E/AndroidRuntime(719):  at android.os.Handler.dispatchMessage(Handler.java:99)
04-02 17:21:39.355: E/AndroidRuntime(719):  at android.os.Looper.loop(Looper.java:130)
04-02 17:21:39.355: E/AndroidRuntime(719):  at android.app.ActivityThread.main(ActivityThread.java:3683)
04-02 17:21:39.355: E/AndroidRuntime(719):  at java.lang.reflect.Method.invokeNative(Native Method)
04-02 17:21:39.355: E/AndroidRuntime(719):  at java.lang.reflect.Method.invoke(Method.java:507)
04-02 17:21:39.355: E/AndroidRuntime(719):  at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:839)
04-02 17:21:39.355: E/AndroidRuntime(719):  at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:597)
04-02 17:21:39.355: E/AndroidRuntime(719):  at dalvik.system.NativeStart.main(Native Method)
04-02 17:21:39.355: E/AndroidRuntime(719): Caused by: android.view.InflateException: Binary XML file line #6: Error inflating class fragment
04-02 17:21:39.355: E/AndroidRuntime(719):  at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:587)
04-02 17:21:39.355: E/AndroidRuntime(719):  at android.view.LayoutInflater.rInflate(LayoutInflater.java:623)
04-02 17:21:39.355: E/AndroidRuntime(719):  at android.view.LayoutInflater.inflate(LayoutInflater.java:408)
04-02 17:21:39.355: E/AndroidRuntime(719):  at android.view.LayoutInflater.inflate(LayoutInflater.java:320)
04-02 17:21:39.355: E/AndroidRuntime(719):  at android.view.LayoutInflater.inflate(LayoutInflater.java:276)
04-02 17:21:39.355: E/AndroidRuntime(719):  at com.android.internal.policy.impl.PhoneWindow.setContentView(PhoneWindow.java:207)
04-02 17:21:39.355: E/AndroidRuntime(719):  at android.app.Activity.setContentView(Activity.java:1657)
04-02 17:21:39.355: E/AndroidRuntime(719):  at com.arun.maps.GoogleMapS.onCreate(GoogleMapS.java:16)
04-02 17:21:39.355: E/AndroidRuntime(719):  at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047)
04-02 17:21:39.355: E/AndroidRuntime(719):  at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1611)
04-02 17:21:39.355: E/AndroidRuntime(719):  ... 11 more
04-02 17:21:39.355: E/AndroidRuntime(719): Caused by: java.lang.IllegalStateException: The meta-data tag in your app's AndroidManifest.xml does not have the right value.  Expected 4323000 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" />
04-02 17:21:39.355: E/AndroidRuntime(719):  at com.google.android.gms.common.GooglePlayServicesUtil.t(Unknown Source)
04-02 17:21:39.355: E/AndroidRuntime(719):  at com.google.android.gms.common.GooglePlayServicesUtil.isGooglePlayServicesAvailable(Unknown Source)
04-02 17:21:39.355: E/AndroidRuntime(719):  at com.google.android.gms.maps.internal.q.B(Unknown Source)
04-02 17:21:39.355: E/AndroidRuntime(719):  at com.google.android.gms.maps.internal.q.A(Unknown Source)
04-02 17:21:39.355: E/AndroidRuntime(719):  at com.google.android.gms.maps.MapsInitializer.initialize(Unknown Source)
04-02 17:21:39.355: E/AndroidRuntime(719):  at com.google.android.gms.maps.SupportMapFragment$b.gW(Unknown Source)
04-02 17:21:39.355: E/AndroidRuntime(719):  at com.google.android.gms.maps.SupportMapFragment$b.a(Unknown Source)
04-02 17:21:39.355: E/AndroidRuntime(719):  at com.google.android.gms.dynamic.a.a(Unknown Source)
04-02 17:21:39.355: E/AndroidRuntime(719):  at com.google.android.gms.dynamic.a.onInflate(Unknown Source)
04-02 17:21:39.355: E/AndroidRuntime(719):  at com.google.android.gms.maps.SupportMapFragment.onInflate(Unknown Source)
04-02 17:21:39.355: E/AndroidRuntime(719):  at android.support.v4.app.FragmentActivity.onCreateView(FragmentActivity.java:290)
04-02 17:21:39.355: E/AndroidRuntime(719):  at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:563)
04-02 17:21:39.355: E/AndroidRuntime(719):  ... 20 more

最佳答案

将此添加到 list 文件的应用程序标记中。

<!-- Required after latest Google Play Services update -->
        <meta-data
            android:name="com.google.android.gms.version"
            android:value="@integer/google_play_services_version" />

关于Android 谷歌地图错误,无法启动 Activity ComponentInfo,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22810714/

相关文章:

Android MyFirstApp + WebView 死于 "Unable to start activity"

java - Watson视觉识别,在java中针对多个分类器进行分类

android - 如何正确设计每侧带有 TextView 的 LinearLayout?

android - 根据当前步行方向旋转 map android google maps

javascript - PHP/MySQL 和 KML,动态生成的标记

ios - GooglePlaces API 使我的应用文件变大了。我能做些什么吗?

java - DatePicker在datepicker中指明出生日期,然后显示下一个生日的天数以及本次生日?

java - 从 ArrayList 中删除对象会导致延迟

javascript - 自定义谷歌地图 V.3 街景控件

java - Android谷歌地图添加标记时出现空指针异常