2012-12-10 40 views
4

我正在使用Eclipse helios和Android 4.1.2 我按照以下文檔https://docs.google.com/document/pub?id=19nQzvKP-CVLd7_VrpwnHfl-AE9fjbJySowONZZtNHzw完成了與tutorial.when中描述的完全相同的代碼。當我在仿真器上運行我的應用程序時,它顯示「This app將不會運行,除非你更新谷歌播放服務「,但在真正的設備,這是索尼Xperia已谷歌播放服務更新版本與」應用程序已停止工作crahses「。任何幫助表示讚賞。Google map android api v2應用程序崩潰

這是我的清單

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

<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參考LIB到我的項目添加google_play_service和android.support.v4 jar文件在我的lib ....請如果我仍然失去anythng認罪SE指南....

我有我maifest添加見上它現在編輯API密鑰...

AMD這裏是從我的手機登錄

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)' 
+0

你有一個API密鑰?我在清單中看不到這部分。 –

+0

我有一個api鍵我編輯了帖子...沒有結果直到現在..我失蹤anythng ... – Durrat

+0

我也做了同樣的,這段代碼不工作。你得到什麼確切的例外? – Harpreet

回答

8

喔...刮傷馬頭這麼久atlast後,我跟隨它的文檔是美妙的,然後得到了解決 使用真實的設備DDMS起初我調試,我發現了以下錯誤

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 

和再經過代碼的幾行有哪些是醒目

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密鑰代碼清單不是應用程序的孩子,其上面的錯誤指出了,然後我REC tified我艙單以下

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

,然後它去像變焦和everythng工作得很好......與實際設備調試幫助了很多...

+0

您的解決方案真的可以幫助我,非常感謝! – acoustic

+0

很高興我能幫你... – Durrat

0

我的錯誤跟蹤已經使用Android Log Viewer (logcat) Application從手機收集應用程序日誌,似乎工作得很好。

+0

這與這個問題有什麼關係? –

+0

爲了在執行應用程序期間診斷崩潰的可能原因,開始查看日誌是一個好習慣。儘管如此,在開發Android應用程序時,它們還不是很方便。使用一個應用程序,例如我提到的那個應用程序。 – gantzer89