Error inflating class fragment Android Map v2

后端 未结 4 1576
忘掉有多难
忘掉有多难 2021-01-23 11:20

I know this is a duplicate question, but solutions from previous post doesn\'t worked for me. Thats why am asking this question.

I am tryi

相关标签:
4条回答
  • 2021-01-23 11:31

    I have download your project from git and after checking i found that you have missed a line which is required to display map Fragment.

    Replace your main activity code with the following code:-

    public class MainActivity extends FragmentActivity {
    private GoogleMap map;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
        map = ((MapFragment) getFragmentManager().findFragmentById(R.id.map))
                .getMap();
    }
    
    0 讨论(0)
  • 2021-01-23 11:31

    Please add these line in your manifest file

         <meta-data
            android:name="com.google.android.gms.version"
            android:value="@integer/google_play_services_version" />
    
        <!-- Goolge API Key -->
         <meta-data
            android:name="com.google.android.maps.v2.API_KEY"
            android:value="your Goolge API key" />
    
    0 讨论(0)
  • 2021-01-23 11:34

    After API 11+, I think you now have have to replace your MapFragment by SupportMapFragment. It would be something like:

    <fragment xmlns:android="http://schemas.android.com/apk/res/android"
     android:id="@+id/map"
     android:layout_width="match_parent"
     android:layout_height="match_parent"
     android:name="com.google.android.gms.maps.SupportMapFragment"/>
    

    Take a look here for further information. Let me know how are you going with.

    0 讨论(0)
  • 2021-01-23 11:42

    This could happen also if you did not define API_KEY for google maps in your manifest file.

    It looks like this:

    `....
    <meta-data
                android:name="com.google.android.maps.v2.API_KEY"
                android:value="<your key>" />
    ....`
    

    Create your key in Google Developer Console

    0 讨论(0)
提交回复
热议问题