My Google Map V2 Test Apps Crashes
i am newcomer on stackoverflow and i have google map test project that use from here and i do just like tutorial but apps crashes. i done every single steps in tutorial and get an
Solution 1:
Change
publicclassMainActivityextendsFragmentActivity {
to
publicclassMainActivityextendsActivity {
Change this
googleMap = ((SupportMapFragment) getSupportFragmentManager().findFragmentById(R.id.map)).getMap();
to
googleMap = ((MapFragment)getFragmentManager().findFragmentById(R.id.map)).getMap();
You also need the below in application tag in manifest
<meta-data
android:name="com.google.android.gms.version"android:value="@integer/google_play_services_version" />
which is a requirement of google play services rev 13
Edit:
Move
<meta-data
android:name="com.google.android.maps.v2.API_KEY"
android:value="AIzaSyBYju6h2BWvZOaSDQpe5f9tv6fJsZy6cY8" />
inside application tag in manifest
Solution 2:
Try with this.
Your MainActivity
privatevoidinitilizeMap() {
if (googleMap == null) {
googleMap = ((SupportMapFragment) getSupportFragmentManager().findFragmentById(R.id.map)).getMap();
// Valida si el mapa no se creo correctamenteif (googleMap == null) {
Toast.makeText(getApplicationContext(), "Sorry! el mapa no pudo ser cargado", Toast.LENGTH_SHORT)
.show();
}
}
}
In your layout this
<?xml version="1.0" encoding="utf-8"?><RelativeLayoutxmlns:android="http://schemas.android.com/apk/res/android"android:layout_width="fill_parent"android:layout_height="fill_parent" ><fragmentandroid:id="@+id/map"android:layout_width="match_parent"android:layout_height="match_parent"class="com.google.android.gms.maps.SupportMapFragment" />
In the manifest, i used this lines in MAC, because in Windows works correctly works without them
<meta-data
android:name="com.google.android.gms.version"android:value="@integer/google_play_services_version" />
Solution 3:
I had a similar problemt. For me adding:
import com.google.android.gms.maps.SupportMapFragment;
And changing the xml to
<fragment
android:name="com.google.android.gms.maps.SupportMapFragment"
android:id="@+id/map"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_below="@+id/header" />
resolved the problem. I hope you resolve it too!
Post a Comment for "My Google Map V2 Test Apps Crashes"