应用程序已停止!谷歌API V2 -地图



我已经按照youtube上的说明创建了一个地图/位置应用程序。我的第一步只是显示地图,但我被卡住了,因为"不幸的是,MyLocApp已经停止了"。我的准则被遵守了。我做错了什么?

清单:

<manifest xmlns:android="http://schemas.android.com/apk/res/android":
        package="tri.mylocapp"
        android:versionCode="1"
        android:versionName="1.0">
    <uses-sdk
        android:minSdkVersion="14"
        android:targetSdkVersion="14" />
    <permission 
        android:name="tri.mylocapp.permission.MAPS_RECEIVE"
        android:protectionLevel="signature"
       />
    <uses-permission android:name="tri.mylocapp.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"/>
    <!-- The following two permissions are not required to use
     Google Maps Android API v2, but are recommended. -->
    <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"/>

    <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="AIzaSyDZIavpm2Kcj4QXnb01qxoZqiEXTBXTABw"/>
        <activity
        android:name="tri.mylocapp.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>

这是布局xml:

<?xml version="1.0" encoding="utf-8"?>
<fragment xmlns:android="http://schemas.android.com/apk/res/android"
          android:id="@+id/map"
          android:layout_width="match_parent"
          android:layout_height="match_parent"
          android:name="com.google.android.gms.maps.MapFragment"/>

这是proguard-project.txt:

-keep class * extends java.util.ListResourceBundle {
    protected Object[][] getContents();
}

这是MainActivity.java:

package tri.mylocapp;
import android.app.Activity;
import android.os.Bundle;
public class MainActivity extends Activity {
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
    }
}

LogCat:

 D/AndroidRuntime(639): Shutting down VM
 W/dalvikvm(639): threadid=1: thread exiting with uncaught exception (group=0x409961f8)
 E/AndroidRuntime(639): FATAL EXCEPTION: main
 E/AndroidRuntime(639): java.lang.RuntimeException: Unable to start activity ComponentInfo{tri.mylocapp/tri.mylocapp.MainActivity}: android.view.InflateException: Binary XML file line #2: Error inflating class fragment
 E/AndroidRuntime(639):     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1955)
 E/AndroidRuntime(639):     at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1980)
 E/AndroidRuntime(639):     at android.app.ActivityThread.access$600(ActivityThread.java:122)
 E/AndroidRuntime(639):     at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1146)
 E/AndroidRuntime(639):     at android.os.Handler.dispatchMessage(Handler.java:99)
 E/AndroidRuntime(639):     at android.os.Looper.loop(Looper.java:137)
 E/AndroidRuntime(639):     at android.app.ActivityThread.main(ActivityThread.java:4340)
 E/AndroidRuntime(639):     at java.lang.reflect.Method.invokeNative(Native Method)
 E/AndroidRuntime(639):     at java.lang.reflect.Method.invoke(Method.java:511)
 E/AndroidRuntime(639):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:784)
 E/AndroidRuntime(639):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:551)
 E/AndroidRuntime(639):     at dalvik.system.NativeStart.main(Native Method)
 E/AndroidRuntime(639): Caused by: android.view.InflateException: Binary XML file line #2: Error inflating class fragment
 E/AndroidRuntime(639):     at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:697)
 E/AndroidRuntime(639):     at android.view.LayoutInflater.inflate(LayoutInflater.java:466)
 E/AndroidRuntime(639):     at android.view.LayoutInflater.inflate(LayoutInflater.java:396)
 E/AndroidRuntime(639):     at android.view.LayoutInflater.inflate(LayoutInflater.java:352)
 E/AndroidRuntime(639):     at com.android.internal.policy.impl.PhoneWindow.setContentView(PhoneWindow.java:251)
 E/AndroidRuntime(639):     at android.app.Activity.setContentView(Activity.java:1835)
 E/AndroidRuntime(639):     at tri.mylocapp.MainActivity.onCreate(MainActivity.java:10)
 E/AndroidRuntime(639):     at android.app.Activity.performCreate(Activity.java:4465)
 E/AndroidRuntime(639):     at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1049)
 E/AndroidRuntime(639):     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1919)
 E/AndroidRuntime(639):     ... 11 more
 E/AndroidRuntime(639): 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" />
  E/AndroidRuntime(639):    at com.google.android.gms.common.GooglePlayServicesUtil.n(Unknown Source)
 E/AndroidRuntime(639):     at com.google.android.gms.common.GooglePlayServicesUtil.isGooglePlayServicesAvailable(Unknown Source)
 E/AndroidRuntime(639):     at com.google.android.gms.maps.internal.q.v(Unknown Source)
 E/AndroidRuntime(639):     at com.google.android.gms.maps.internal.q.u(Unknown Source)
 E/AndroidRuntime(639):     at com.google.android.gms.maps.MapsInitializer.initialize(Unknown Source)
 E/AndroidRuntime(639):     at com.google.android.gms.maps.MapFragment$b.ex(Unknown Source)
 E/AndroidRuntime(639):     at com.google.android.gms.maps.MapFragment$b.a(Unknown Source)
 E/AndroidRuntime(639):     at com.google.android.gms.dynamic.a.a(Unknown Source)
 E/AndroidRuntime(639):     at com.google.android.gms.dynamic.a.onInflate(Unknown Source)
 E/AndroidRuntime(639):     at com.google.android.gms.maps.MapFragment.onInflate(Unknown Source)
 E/AndroidRuntime(639):     at android.app.Activity.onCreateView(Activity.java:4242)
 E/AndroidRuntime(639):     at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:673)
 E/AndroidRuntime(639):     ... 20 more
 I/Process(639): Sending signal. PID: 639 SIG: 9

你的日志上清楚地写着

.818: E/AndroidRuntime(639): 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" />
 03-20 17:11:43.818:icesUtil.isGooglePlayServicesAvailable(Unknown 

将Google Play服务版本添加到应用程序的清单

编辑应用程序的AndroidManifest.xml文件,并添加元素中的下列声明。的版本

应用编译时使用的Google Play服务。

您需要将<application>标签下的<meta-data>添加到AndroidManifest.xml

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

这是因为最新的google play服务需要一个版本名,这是在AndroidManifest.xml中使用<meta-data .. />来提到的

构建您的manifest.xml如下:

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

在manifest中的activity声明中将locap改为locapp

相关内容

  • 没有找到相关文章

最新更新