4

因此,我正在關注Google maps API v2 for android,試圖在屏幕上獲取基本地圖。在遵循所有步驟之後,我得到了「錯誤膨脹類碎片」。其他人遇到同樣的問題,但沒有任何解決方案似乎工作。 確切錯誤:android.view.InflateException: Binary XML file line #10: Error inflating class fragment在android上設置谷歌地圖API v2,錯誤膨脹類片段

的.java:

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


public class GoogleMaps extends FragmentActivity { 

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

    @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_maps, menu); 
     return true; 
    } 

} 

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=".GoogleMaps" > 
    <fragment 
     android:id="@+id/map" 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" 
     class="com.google.android.gms.maps.SupportMapFragment" 
     android:name="com.testing.svma.MainActivity"/> 
</RelativeLayout> 

我想我已經設置了谷歌正常播放服務,它要求下載這些網頁時導航到第一次。這裏是我的project.properties:

# Project target. 
target=android-17 
android.library=false 
android.library.reference.1=../../../android-sdks/extras/google/google_play_services/libproject/google-play-services_lib 

日誌貓:

... 
03-06 21:12:44.751: I/System.out(9122): Debugger has connected 
03-06 21:12:44.751: I/System.out(9122): waiting for debugger to settle... 
03-06 21:12:46.166: I/System.out(9122): debugger has settled (1487) 
03-06 21:12:50.634: D/dalvikvm(9122): DexOpt: couldn't find field Landroid/content/res/Configuration;.smallestScreenWidthDp 
03-06 21:12:50.634: W/dalvikvm(9122): VFY: unable to resolve instance field 23 
03-06 21:12:50.634: D/dalvikvm(9122): VFY: replacing opcode 0x52 at 0x0012 
03-06 21:12:50.634: D/dalvikvm(9122): VFY: dead code 0x0014-0018 in Lcom/google/android/gms/common/GooglePlayServicesUtil;.b (Landroid/content/res/Resources;)Z 
03-06 21:12:51.126: W/dalvikvm(9122): Unable to resolve superclass of Lmaps/p/s; (427) 
03-06 21:12:51.126: W/dalvikvm(9122): Link of class 'Lmaps/p/s;' failed 
03-06 21:12:51.126: W/dalvikvm(9122): Unable to resolve superclass of Lmaps/y/bo; (3820) 
03-06 21:12:51.126: W/dalvikvm(9122): Link of class 'Lmaps/y/bo;' failed 
03-06 21:12:51.126: W/dalvikvm(9122): Unable to resolve superclass of Lmaps/i/k; (4208) 
03-06 21:12:51.126: W/dalvikvm(9122): Link of class 'Lmaps/i/k;' failed 
03-06 21:12:51.126: E/dalvikvm(9122): Could not find class 'maps.i.k', referenced from method maps.z.ag.a 
03-06 21:12:51.126: W/dalvikvm(9122): VFY: unable to resolve new-instance 3540 (Lmaps/i/k;) in Lmaps/z/ag; 
03-06 21:12:51.126: D/dalvikvm(9122): VFY: replacing opcode 0x22 at 0x006d 
03-06 21:12:51.149: D/dalvikvm(9122): VFY: dead code 0x006f-007f in Lmaps/z/ag;.a (Landroid/view/LayoutInflater;Lcom/google/android/gms/maps/GoogleMapOptions;ZLjava/lang/String;)Lmaps/z/ag; 

我試圖從這些線程解決方案,沒有運氣:

Error inflating class fragment

Google Maps V2 - Error inflating class Fragment

我也只是遵循這個教程,並得到了同樣的錯誤:

https://www.youtube.com/watch?v=OZRgiwGfvSQ

+0

同樣在這裏!你有這個工作嗎? – 2013-03-14 07:51:05

+0

是的,不知道如何,做了幾件事......你是否將Google播放服務庫複製到項目目錄中,而不是在sdk目錄中引用它? – 2013-03-14 19:38:37

+0

我有這個例子,使用googlemaps v2和一個Activity,使用FragmentActivity爲較低的操作系統和更高版本提供最新的Android支持庫。這很困難,但可能。看看這個例子:http://android-er.blogspot.com/2012/12/using-supportmapfragment.html – papachan 2013-08-27 17:06:13

回答

0

按照本link

所有步驟你已經錯過了引用谷歌地圖 在你的代碼

public class GoogleMaps extends FragmentActivity { 
    private GoogleMap mMap; 
    @Override 
    protected void onCreate(Bundle savedInstanceState) { 
     super.onCreate(savedInstanceState); 
     setContentView(R.layout.activity_google_maps); 
     mMap = ((SupportMapFragment) getSupportFragmentManager().findFragmentById(R.id.map)) 
        .getMap(); 
    } 

    @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_maps, menu); 
     return true; 
    } 

} 

不是添加地圖鍵其他加入這一點,添加播放服務到項目

1

這個問題通常來自於你的專業目標缺少android-support庫。發生這種情況是因爲在舊版本的api片段中不存在,因此您需要添加此庫以在舊版Android中添加對片段的支持。

要做到這一點鼠標右鍵點擊你的項目,然後:

enter image description here

此外,你可以去在這篇博客文章中,我在您的應用程序中實現谷歌地圖中寫道:

Google Maps API V2

0

我有相同的錯誤,並設法解決它與來自差異stackoverflow答案的多次嘗試:

不知道這是/是一個可以幫助解決這個問題,但我只列出我曾經做過的事情:

  • 右鍵單擊項目 - >屬性 - > Android的 - >更改項目建設目標到Android 4.1。2(Android開放源代碼項目) - >在庫下,刪除谷歌播放服務庫並添加它 - >點擊「應用」 - >按「確定」
  • 右鍵項目 - > Android工具 - >修復項目屬性(由Emil Adz
  • 參考了谷歌地圖類(由Basavaraj Hampali

    private GoogleMap mMap; 
    
    mMap = ((SupportMapFragment) this.getSupportFragmentManager().findFragmentById(R.id.map)).getMap(); 
    if (mMap== null) { 
        Toast.makeText(this,"Map not Available", Toast.LENGTH_LONG).show(); 
    } 
    
  • 延伸,而不是僅僅 「FragmentActivity」 android.support.v4.app.FragmentActivity(由ayush1794

    extends android.support.v4.app.FragmentActivity 
    

希望它能幫助:)

1

我有同樣的問題,並試圖每個possiblty如2天,但我改變了我的佈局xml文件一樣,在Java代碼中,我用supportmapfragment

還進口從包瀏覽器Android的支持庫

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

<fragment 
     android:name="com.google.android.gms.maps.SupportMapFragment" 

     android:id="@+id/map" 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" /> 
</LinearLayout> 
1

我已經在清單中添加這些線固定這一問題。

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