Reputation: 7987
I'm trying to use the Google Maps API v2 in an android project that targets the v10 API. Reading the dev guide it is said that, since Fragments have been introduced only in android api 11, I need to use the Android Support Library to use the API.
So I did the following:
-Included the android support library v4 jar to my project
-Included the "google-play-services-lib" library project and referenced it
-Wrote the following code, taken from the dev guide:
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
}
The problem arises on the last line of code, as the comment points out. When I add that the following error appears in Eclipse (not on that line, but at the top of the file):
The type android.app.Fragment cannot be resolved. It is indirectly referenced from required .class files
and Eclipse refuses to compile the project.
I've tried every possible configuration I can think of in the project setup, but maybe something is eluding me... what am I doing wrong? I found some with similar problem online but no solution, or at least no solution they proposed worked for me.
Upvotes: 3
Views: 4994
Reputation: 1007534
Use SupportMapFragment
, not MapFragment
, when you are using the Android Support package's fragment backport.
Upvotes: 7