Android Google Map V2已停止

时间:2014-03-21 14:57:44

标签: android google-maps android-intent android-fragments android-maps-v2

我正在尝试构建地图应用并逐步跟随this link。我在这里找到了类似的主题,但没有帮助我。我想显示地图,但是当我运行它时,它会返回强制关闭和我的Android设备。我看到很多关于这个错误的问题,但没有人真正回答我的问题。这是我的LogCat:

03-21 20:55:57.476: D/AndroidRuntime(4090): Shutting down VM
03-21 20:55:57.476: W/dalvikvm(4090): threadid=1: thread exiting with uncaught exception (group=0x417692a0)
03-21 20:55:57.500: E/AndroidRuntime(4090): FATAL EXCEPTION: main
03-21 20:55:57.500: E/AndroidRuntime(4090): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.mapandroid/com.example.mapandroid.MainActivity}: android.view.InflateException: Binary XML file line #11: Error inflating class fragment
03-21 20:55:57.500: E/AndroidRuntime(4090):     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2097)
03-21 20:55:57.500: E/AndroidRuntime(4090):     at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2122)
03-21 20:55:57.500: E/AndroidRuntime(4090):     at android.app.ActivityThread.access$600(ActivityThread.java:140)
03-21 20:55:57.500: E/AndroidRuntime(4090):     at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1228)
03-21 20:55:57.500: E/AndroidRuntime(4090):     at android.os.Handler.dispatchMessage(Handler.java:99)
03-21 20:55:57.500: E/AndroidRuntime(4090):     at android.os.Looper.loop(Looper.java:137)
03-21 20:55:57.500: E/AndroidRuntime(4090):     at android.app.ActivityThread.main(ActivityThread.java:4895)
03-21 20:55:57.500: E/AndroidRuntime(4090):     at java.lang.reflect.Method.invokeNative(Native Method)
03-21 20:55:57.500: E/AndroidRuntime(4090):     at java.lang.reflect.Method.invoke(Method.java:511)
03-21 20:55:57.500: E/AndroidRuntime(4090):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:994)
03-21 20:55:57.500: E/AndroidRuntime(4090):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:761)
03-21 20:55:57.500: E/AndroidRuntime(4090):     at dalvik.system.NativeStart.main(Native Method)
03-21 20:55:57.500: E/AndroidRuntime(4090): Caused by: android.view.InflateException: Binary XML file line #11: Error inflating class fragment
03-21 20:55:57.500: E/AndroidRuntime(4090):     at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:704)
03-21 20:55:57.500: E/AndroidRuntime(4090):     at android.view.LayoutInflater.rInflate(LayoutInflater.java:746)
03-21 20:55:57.500: E/AndroidRuntime(4090):     at android.view.LayoutInflater.inflate(LayoutInflater.java:489)
03-21 20:55:57.500: E/AndroidRuntime(4090):     at android.view.LayoutInflater.inflate(LayoutInflater.java:396)
03-21 20:55:57.500: E/AndroidRuntime(4090):     at com.example.mapandroid.MainActivity$PlaceholderFragment.onCreateView(MainActivity.java:67)
03-21 20:55:57.500: E/AndroidRuntime(4090):     at android.support.v4.app.Fragment.performCreateView(Fragment.java:1500)
03-21 20:55:57.500: E/AndroidRuntime(4090):     at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:927)
03-21 20:55:57.500: E/AndroidRuntime(4090):     at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:1104)
03-21 20:55:57.500: E/AndroidRuntime(4090):     at android.support.v4.app.BackStackRecord.run(BackStackRecord.java:682)
03-21 20:55:57.500: E/AndroidRuntime(4090):     at android.support.v4.app.FragmentManagerImpl.execPendingActions(FragmentManager.java:1467)
03-21 20:55:57.500: E/AndroidRuntime(4090):     at android.support.v4.app.FragmentActivity.onStart(FragmentActivity.java:570)
03-21 20:55:57.500: E/AndroidRuntime(4090):     at android.app.Instrumentation.callActivityOnStart(Instrumentation.java:1178)
03-21 20:55:57.500: E/AndroidRuntime(4090):     at android.app.Activity.performStart(Activity.java:5173)
03-21 20:55:57.500: E/AndroidRuntime(4090):     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2070)
03-21 20:55:57.500: E/AndroidRuntime(4090):     ... 11 more
03-21 20:55:57.500: E/AndroidRuntime(4090): 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  element:     
03-21 20:55:57.500: E/AndroidRuntime(4090):     at com.google.android.gms.common.GooglePlayServicesUtil.n(Unknown Source)
03-21 20:55:57.500: E/AndroidRuntime(4090):     at com.google.android.gms.common.GooglePlayServicesUtil.isGooglePlayServicesAvailable(Unknown Source)
03-21 20:55:57.500: E/AndroidRuntime(4090):     at com.google.android.gms.maps.internal.q.v(Unknown Source)
03-21 20:55:57.500: E/AndroidRuntime(4090):     at com.google.android.gms.maps.internal.q.u(Unknown Source)
03-21 20:55:57.500: E/AndroidRuntime(4090):     at com.google.android.gms.maps.MapsInitializer.initialize(Unknown Source)
03-21 20:55:57.500: E/AndroidRuntime(4090):     at com.google.android.gms.maps.SupportMapFragment$b.ex(Unknown Source)
03-21 20:55:57.500: E/AndroidRuntime(4090):     at com.google.android.gms.maps.SupportMapFragment$b.a(Unknown Source)
03-21 20:55:57.500: E/AndroidRuntime(4090):     at com.google.android.gms.dynamic.a.a(Unknown Source)
03-21 20:55:57.500: E/AndroidRuntime(4090):     at com.google.android.gms.dynamic.a.onInflate(Unknown Source)
03-21 20:55:57.500: E/AndroidRuntime(4090):     at com.google.android.gms.maps.SupportMapFragment.onInflate(Unknown Source)
03-21 20:55:57.500: E/AndroidRuntime(4090):     at android.support.v4.app.FragmentActivity.onCreateView(FragmentActivity.java:290)
03-21 20:55:57.500: E/AndroidRuntime(4090):     at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:676)
03-21 20:55:57.500: E/AndroidRuntime(4090):     ... 24 more
03-21 20:55:57.515: D/dalvikvm(4090): GC_CONCURRENT freed 233K, 10% free 7615K/8455K, paused 13ms+2ms, total 39ms
03-21 21:36:53.375: W/dalvikvm(4279): VFY: unable to resolve static field 3202 (MapAttrs) in Lcom/google/android/gms/R$styleable;
03-21 21:36:53.375: D/dalvikvm(4279): VFY: replacing opcode 0x62 at 0x000e
03-21 21:36:53.375: D/AndroidRuntime(4279): Shutting down VM
03-21 21:36:53.375: W/dalvikvm(4279): threadid=1: thread exiting with uncaught exception (group=0x417692a0)
03-21 21:36:53.382: E/AndroidRuntime(4279): FATAL EXCEPTION: main
03-21 21:36:53.382: E/AndroidRuntime(4279): java.lang.NoClassDefFoundError: com.google.android.gms.R$styleable
03-21 21:36:53.382: E/AndroidRuntime(4279):     at com.google.android.gms.maps.GoogleMapOptions.createFromAttributes(Unknown Source)
03-21 21:36:53.382: E/AndroidRuntime(4279):     at com.google.android.gms.maps.SupportMapFragment.onInflate(Unknown Source)
03-21 21:36:53.382: E/AndroidRuntime(4279):     at android.support.v4.app.FragmentActivity.onCreateView(FragmentActivity.java:290)
03-21 21:36:53.382: E/AndroidRuntime(4279):     at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:676)
03-21 21:36:53.382: E/AndroidRuntime(4279):     at android.view.LayoutInflater.rInflate(LayoutInflater.java:746)
03-21 21:36:53.382: E/AndroidRuntime(4279):     at android.view.LayoutInflater.inflate(LayoutInflater.java:489)
03-21 21:36:53.382: E/AndroidRuntime(4279):     at android.view.LayoutInflater.inflate(LayoutInflater.java:396)
03-21 21:36:53.382: E/AndroidRuntime(4279):     at com.example.map.MainActivity$PlaceholderFragment.onCreateView(MainActivity.java:57)
03-21 21:36:53.382: E/AndroidRuntime(4279):     at android.support.v4.app.Fragment.performCreateView(Fragment.java:1500)
03-21 21:36:53.382: E/AndroidRuntime(4279):     at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:927)
03-21 21:36:53.382: E/AndroidRuntime(4279):     at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:1104)
03-21 21:36:53.382: E/AndroidRuntime(4279):     at android.support.v4.app.BackStackRecord.run(BackStackRecord.java:682)
03-21 21:36:53.382: E/AndroidRuntime(4279):     at android.support.v4.app.FragmentManagerImpl.execPendingActions(FragmentManager.java:1467)
03-21 21:36:53.382: E/AndroidRuntime(4279):     at android.support.v4.app.FragmentActivity.onStart(FragmentActivity.java:570)
03-21 21:36:53.382: E/AndroidRuntime(4279):     at android.app.Instrumentation.callActivityOnStart(Instrumentation.java:1178)
03-21 21:36:53.382: E/AndroidRuntime(4279):     at android.app.Activity.performStart(Activity.java:5173)
03-21 21:36:53.382: E/AndroidRuntime(4279):     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2070)
03-21 21:36:53.382: E/AndroidRuntime(4279):     at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2122)
03-21 21:36:53.382: E/AndroidRuntime(4279):     at android.app.ActivityThread.access$600(ActivityThread.java:140)
03-21 21:36:53.382: E/AndroidRuntime(4279):     at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1228)
03-21 21:36:53.382: E/AndroidRuntime(4279):     at android.os.Handler.dispatchMessage(Handler.java:99)
03-21 21:36:53.382: E/AndroidRuntime(4279):     at android.os.Looper.loop(Looper.java:137)
03-21 21:36:53.382: E/AndroidRuntime(4279):     at android.app.ActivityThread.main(ActivityThread.java:4895)
03-21 21:36:53.382: E/AndroidRuntime(4279):     at java.lang.reflect.Method.invokeNative(Native Method)
03-21 21:36:53.382: E/AndroidRuntime(4279):     at java.lang.reflect.Method.invoke(Method.java:511)
03-21 21:36:53.382: E/AndroidRuntime(4279):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:994)
03-21 21:36:53.382: E/AndroidRuntime(4279):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:761)
03-21 21:36:53.382: E/AndroidRuntime(4279):     at dalvik.system.NativeStart.main(Native Method)

和我的MainActivity.java

package com.example.map;

import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentActivity;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.view.ViewGroup;


public class MainActivity extends FragmentActivity {

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

        if (savedInstanceState == null) {
            getSupportFragmentManager().beginTransaction()
                    .add(R.id.container, new PlaceholderFragment()).commit();
        }
    }

    @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;
    }

    @Override
    public boolean onOptionsItemSelected(MenuItem item) {
        // Handle action bar item clicks here. The action bar will
        // automatically handle clicks on the Home/Up button, so long
        // as you specify a parent activity in AndroidManifest.xml.
        int id = item.getItemId();
        if (id == R.id.action_settings) {
            return true;
        }
        return super.onOptionsItemSelected(item);
    }

    /**
     * A placeholder fragment containing a simple view.
     */
    public static class PlaceholderFragment extends Fragment {

        public PlaceholderFragment() {
        }

        @Override
        public View onCreateView(LayoutInflater inflater, ViewGroup container,
                Bundle savedInstanceState) {
            View rootView = inflater.inflate(R.layout.fragment_main, container,
                    false);
            return rootView;
        }
    }

}

这是我的activity_main.xml:

<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/container"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context="com.example.map.MainActivity"
tools:ignore="MergeRootFrame" />

这是我的fragment_main.xml

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
tools:context="com.example.map.MainActivity$PlaceholderFragment" >



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

</RelativeLayout>

和我的清单:

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

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

<permission android:name="com.example.map.permission.MAPS_RECEIVE" android:protectionLevel="signature"/>
<uses-permission android:name="com.example.map.permission.MAPS_RECEIVE"/>
<uses-permission android:name="android.permission.INTERNET" />
<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"/>

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

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

<application
    android:allowBackup="true"
    android:icon="@drawable/ic_launcher"
    android:label="@string/app_name"
    android:theme="@style/AppTheme" >
    <activity
        android:name="com.example.map.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>
</application>

</manifest>

我从以下链接一步一步地阅读,但在我的代码中似乎有很多错误。我想念的是什么?有什么建议吗?非常感谢。

2 个答案:

答案 0 :(得分:2)

移动此

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

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

到你的&lt;之间应用程序&gt;&LT; /应用程序&gt;标签

答案 1 :(得分:1)

  

com.google.android.gms.R $设置样式

这通常是由于没有正确引用Google Play服务

  

引起:java.lang.IllegalStateException:您的元数据标记   应用程序的AndroidManifest.xml没有正确的值。预期   4242000但找到0.您必须在其中包含以下声明   元素:

您还缺少2个元标记作为清单文件

的应用程序标记的子标记
<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.v2.API_KEY"
 android:value="your api key"/>
 <meta-data 
 android:name="com.google.android.gms.version"
 android:value="@integer/google_play_services_version" />
 <activity
    android:name="com.example.map.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>
 </application>
  

在android中编写@ integer / google_play_services_version是正确的   值?

是。检查库项目的res /值中的version.xml。将如下所示。

<?xml version="1.0" encoding="utf-8"?>
<resources>
    <integer name="google_play_services_version">4030500</integer>
</resources>

您需要做的就是引用与

相同的内容
 android:value="@integer/google_play_services_version" /> 
 // this is what should be in the application tag of manifest file