I am try to add Google MAP Api v2 in my application.but I am getting exception. Exception is
java.lang.RuntimeException: Unable to start activity Component
You should use SupportMapFragment
instead of MapFragment
.
Change
<fragment
android:id="@+id/map"
android:name="com.google.android.gms.maps.MapFragment"
android:layout_width="match_parent"
android:layout_height="match_parent"/>
to
<fragment
android:id="@+id/map"
android:name="com.google.android.gms.maps.SupportMapFragment"
android:layout_width="match_parent"
android:layout_height="match_parent"/>
Also change
_googleMap=((MapFragment)getFragmentManager().findFragmentById(R.id.map)).getMap();
to
_googleMap = ((SupportMapFragment) getSupportFragmentManager().findFragmentById(
R.id.map)).getMap();
And also If you're using fragments on older devices (pre Honeycomb) you should always extend your Activity
from FragmentActivity
.
and also check
Add the Google Play services version to your app's manifest
Edit your application's AndroidManifest.xml file, and add the following declaration within the element. This embeds the version of Google Play services that the app was compiled with.
You just need to add <meta-data>
under <application>
tag into your AndroidManifest.xml
....<application>
<meta-data android:name="com.google.android.gms.version"
android:value="@integer/google_play_services_version" />
</application>
This is because latest google play services requires a version name, which is to be mentioned using <meta-data .. /> inside AndroidManifest.xml
In your xml try to change from
android:name="com.google.android.gms.maps.MapFragment"
to
android:name="com.google.android.gms.maps.SupportMapFragment"
Check if this work.
Extend your MainActivity from FragmentActivity.
Refer this :
Inflating Google Maps v2 fragment causes ClassNotFoundException
If you are using Fragments your MainActivity
must extends FragmentActivity
:
public class MainActivity extends FragmentActivity {
//Stuff
}
If you are using the Support-Library so you can use your Fragments in lower Android API Levels use This:
public class MainActivity extends android.support.v4.app.FragmentActivity{
//Stuff
}
And use the SupportFragmentMap in your XML:
<fragment
android:id="@+id/map"
android:name="com.google.android.gms.maps.SupportMapFragment"
android:layout_width="match_parent"
android:layout_height="match_parent"/>