3

我正在嘗試在面向v10 API的android項目中使用Google Maps API v2。 閱讀開發指南據說,由於Fragments僅在android api 11中引入,我需要使用Android支持庫來使用API​​。Android支持庫v4和Google Maps API中斷編譯

所以我做了以下內容:
-Included Android的支持庫V4罐子到我的項目
-Included「谷歌播放服務-lib的」庫項目,並引用它
-Wrote下面的代碼,取自開發指南:

package com.darco.darcoapp; 

import com.google.android.gms.maps.GoogleMap; 
import com.google.android.gms.maps.MapFragment; 

import android.os.Bundle; 
import android.support.v4.app.Fragment; 
import android.support.v4.app.FragmentManager; 

public class CardJourneyActivity extends FragmentActivity{ 
    private GoogleMap myGoogleMap; 

    @Override 
    protected void onCreate(Bundle savedInstanceState) { 
     super.onCreate(savedInstanceState); 

     setContentView(R.layout.activity_card_journey); 

     FragmentManager fm = getSupportFragmentManager(); 
     Fragment fr = fm.findFragmentById(R.id.mapFragmentCardJourney); 
     MapFragment mf = (MapFragment)fr; //this line causes the compilation error 

    } 

問題出現在最後一行代碼中,正如註釋所指出的那樣。 當我補充一點,在Eclipse中出現以下錯誤(沒有上線,但在該文件的頂部):

The type android.app.Fragment cannot be resolved. It is indirectly referenced from required .class files 

和Eclipse拒絕編譯該項目。

我已經嘗試了所有可能的配置,我可以在項目設置中想到,但也許有什麼東西在逃避我......我做錯了什麼?我在網上發現了一些類似的問題,但沒有解決方案,或者至少沒有他們提出的解決方案爲我工作。

回答

7

使用SupportMapFragment而不是MapFragment,當您使用Android支持包的片段backport時。

+0

這麼容易,但不知道我被難住了。謝謝! –