谷歌地图android api v2应用程序崩溃 [英] Google map android api v2 application crashes

查看:23
本文介绍了谷歌地图android api v2应用程序崩溃的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用的是 Eclipse helios 和 Android 4.1.2我遵循了以下文档 https://docs.google.com/document/pub?id=19nQzvKP-CVLd7_VrpwnHfl-AE9fjbJySowONZZtNHzw 并完全按照教程中的描述完成编码.是 sony xperia,它有谷歌播放服务更新版本,它崩溃了应用程序已停止工作".感谢任何帮助.

I am using Eclipse helios and Android 4.1.2 i have followed the following documentation https://docs.google.com/document/pub?id=19nQzvKP-CVLd7_VrpwnHfl-AE9fjbJySowONZZtNHzw and done the coding exactly as described in tutorial.when i run my app on emulator it shows "This app wont run unless you update google play services" but on real device which is sony xperia which has google play services updated version it crahses with "App has stopped working".Any help is appreciated.

这是我的清单

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


    <uses-sdk
        android:minSdkVersion="11"
        android:targetSdkVersion="16" />

      <uses-permission android:name="android.permission.INTERNET" />
    <uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
    <uses-permission android:name="android.permission.ACCESS_CORSE_LOCATION" />

    <uses-feature android:glEsVersion="0x00020000" android:required="true"/>
     <permission
         android:name="com.example.emeterfinalapp.permission.MAPS_RECEIVE"
         android:protectionLevel="signature"/>
<uses-permission  android:name="com.example.emeterfinalapp.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"/>


    <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.example.emeterfinalapp.EmeterMainActivity"
            android:configChanges="orientation|keyboardHidden|screenSize"
            android:label="@string/app_name"
            android:theme="@style/FullscreenTheme" >
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />

                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
        <activity
            android:name="com.example.emeterfinalapp.EnterLocationActivity"
            android:label="@string/title_activity_enter_location"
            android:parentActivityName="com.example.emeterfinalapp.EmeterMainActivity" >
            <meta-data
                android:name="android.support.PARENT_ACTIVITY"
                android:value="com.example.emeterfinalapp.EmeterMainActivity" />
        </activity>

        <activity
            android:name="com.example.emeterfinalapp.SelectLocation"
            android:label="@string/title_activity_select_location"
            android:parentActivityName="com.example.emeterfinalapp.EnterMainActivity" >
            <meta-data
                android:name="android.support.PARENT_ACTIVITY"
                android:value="com.example.emeterfinalapp.EnterMainActivity" />


         </activity>
        </application>
 <meta-data
   android:name="com.google.android.maps.v2.API_KEY"
   android:value="my api key"/>
    </manifest>

这是我的 main.xml

here is my 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"
    tools:context=".SelectLocation" >

    <Button
        android:id="@+id/satellite_button"
        android:layout_width="250dp"
        android:layout_height="wrap_content"
        android:layout_alignParentRight="true"
        android:layout_alignParentTop="true"
        android:layout_toRightOf="@+id/mapview_button"
        android:text="@string/satellitebuttontext" />


        <fragment xmlns:android="http://schemas.android.com/apk/res/android"
         android:id="@+id/map"
         android:layout_width="match_parent"
         android:layout_height="match_parent"
         class="com.google.android.gms.maps.SupportMapFragment"
         android:layout_below="@+id/satellite_button"/>


        <LinearLayout android:id="@+id/zoom" 
        android:layout_width="wrap_content" 
        android:layout_height="wrap_content" 
        android:layout_alignParentBottom="true" 
        android:layout_centerHorizontal="true" 
        />

        <Button
            android:id="@+id/mapview_button"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_alignParentLeft="true"
            android:layout_alignParentTop="true"
            android:text="@string/mapbuttontext" />

</RelativeLayout>

这是我的活动

    package com.example.emeterfinalapp;

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

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

        public class SelectLocation extends FragmentActivity  {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_select_location);
        // Show the Up button in the action bar.
        getActionBar().setDisplayHomeAsUpEnabled(true);
                                           GooglePlayServicesUtil.isGooglePlayServicesAvailable(getApplicationContext());

        GoogleMap map = ((SupportMapFragment)          getSupportFragmentManager().findFragmentById(R.id.map)).getMap();

    }


}

我将 google_play_services 库引用到我的项目中,在我的库中添加了 google_play_service 和 android.support.v4 jar 文件....如果我仍然缺少任何东西,请指导....

I gave reference of google_play_services lib to my project added google_play_service and android.support.v4 jar files in my lib....Please if i m still missing anythng please guide....

我在 maifest 中添加了 api 密钥,请参阅上面的已编辑...

I have api key which i have added in maifest see above its edited now...

这里是我手机日志中的错误跟踪

amd here is the error trace from my phone log

  I/ActivityManager(  282): Displayed com.example.emeterfinalapp/.EmeterMainActivity:                +206ms
     I/ActivityManager(  282): Displayed com.example.emeterfinalapp/.EnterLocationActivity:      +224ms
     W/InputDispatcher(  282): channel '2c3dbfd0      com.example.emeterfinalapp/com.example.emeterfinalapp.EmeterMainActivity (server)' ~           Consumer closed input channel or an error occurred.  events=0x8
     E/InputDispatcher(  282): channel '2c3dbfd0      com.example.emeterfinalapp/com.example.emeterfinalapp.EmeterMainActivity (server)' ~      Channel is unrecoverably broken and will be disposed!
     W/InputDispatcher(  282): Attempted to unregister already unregistered input channel      '2c3dbfd0 com.example.emeterfinalapp/com.example.emeterfinalapp.EmeterMainActivity      (server)'
     W/InputDispatcher(  282): channel '2c504fb8      com.example.emeterfinalapp/com.example.emeterfinalapp.EnterLocationActivity (server)' ~      Consumer closed input channel or an error occurred.  events=0x8
     E/InputDispatcher(  282): channel '2c504fb8      com.example.emeterfinalapp/com.example.emeterfinalapp.EnterLocationActivity (server)' ~      Channel is unrecoverably broken and will be disposed!
     W/InputDispatcher(  282): Attempted to unregister already unregistered input channel      '2c504fb8 com.example.emeterfinalapp/com.example.emeterfinalapp.EnterLocationActivity      (server)'

推荐答案

Whoo...在挠了马头这么久之后我终于找到了解决方案首先,我按照其文档使用 DDMS 对真实设备进行了调试,这非常棒,然后我发现了以下错误

Whoo...after scratching ma head for so long atlast i got the solution first i did debugging with real device using DDMS following its documentation which is fabulous then i discovered the following error

12-12 15:08:29.458: E/AndroidRuntime(26382): java.lang.RuntimeException: Unable to start     activity ComponentInfo{com.example.emeterfinalapp/com.example.emeterfinalapp.SelectLocation}:     android.view.InflateException: Binary XML file line #17: Error inflating class fragment

然后在几行代码之后出现了另一个引人注目的错误

and then after few more lines of code there was another error which was eye catching

12-12 15:08:29.458: E/AndroidRuntime(26382): Caused by: java.lang.RuntimeException: API key not found.  Check that <meta-data android:name="com.google.android.maps.v2.API_KEY" android:value="your API key"/> is in the <application> element of AndroidManifest.xml

然后我意识到我的 api 密钥代码是上述错误指出的清单而不是应用程序的子项,然后我将清单纠正为以下

and then i realised that my api key code is a child of manifest not application which the above error pointed out and then i rectified my manifest to following

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


<uses-sdk
    android:minSdkVersion="11"
    android:targetSdkVersion="16" />

  <uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_CORSE_LOCATION" />

<uses-feature android:glEsVersion="0x00020000" android:required="true"/>
 <permission
     android:name="com.example.emeterfinalapp.permission.MAPS_RECEIVE"
     android:protectionLevel="signature"/>
<uses-permission  android:name="com.example.emeterfinalapp.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"/>


<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.example.emeterfinalapp.EmeterMainActivity"
        android:configChanges="orientation|keyboardHidden|screenSize"
        android:label="@string/app_name"
        android:theme="@style/FullscreenTheme" >
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />

            <category android:name="android.intent.category.LAUNCHER" />
        </intent-filter>
    </activity>
    <activity
        android:name="com.example.emeterfinalapp.EnterLocationActivity"
        android:label="@string/title_activity_enter_location"
        android:parentActivityName="com.example.emeterfinalapp.EmeterMainActivity" >
        <meta-data
            android:name="android.support.PARENT_ACTIVITY"
            android:value="com.example.emeterfinalapp.EmeterMainActivity" />
    </activity>

    <activity
        android:name="com.example.emeterfinalapp.SelectLocation"
        android:label="@string/title_activity_select_location"
        android:parentActivityName="com.example.emeterfinalapp.EnterMainActivity" >
        <meta-data
            android:name="android.support.PARENT_ACTIVITY"
            android:value="com.example.emeterfinalapp.EnterMainActivity" />
    </activity>

     <meta-data
   android:name="com.google.android.maps.v2.API_KEY"
   android:value="my api key"/>
</application>

然后它就像缩放一样,一切都完美无缺......使用真实设备进行调试有很大帮助......

and then it went like a zoom and everythng worked just perfectly...Debugging with real device helped a lot...

这篇关于谷歌地图android api v2应用程序崩溃的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆