Android google map

后端 未结 4 968
陌清茗
陌清茗 2020-12-06 23:53

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         


        
相关标签:
4条回答
  • 2020-12-07 00:28

    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

    0 讨论(0)
  • 2020-12-07 00:28

    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.

    0 讨论(0)
  • 2020-12-07 00:32

    Extend your MainActivity from FragmentActivity.

    Refer this :

    Inflating Google Maps v2 fragment causes ClassNotFoundException

    0 讨论(0)
  • 2020-12-07 00:39

    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"/>
    
    0 讨论(0)
提交回复
热议问题