1

Пробовал столько раз, чтобы избежать этой ошибки, шины все еще не могут найти ответ на этот вопрос. Это мое первое приложение с API Google. и я хотел просто отобразить карту на экране. Я получаю ошибку «раздувание класса» и пытался найти множество решений, которые я нашел, но все же я получаю ту же ошибку. пожалуйста помоги !Ошибка раздувания фрагмента класса.

MainActivity.java

package com.example.testmap; 

import com.google.android.gms.maps.GoogleMap; 

import android.os.Bundle; 
import android.app.Activity; 
import android.view.Menu; 
import android.widget.Toast; 
import com.google.android.gms.maps.MapFragment; 

public class MainActivity extends Activity { 

    private GoogleMap googleMap; 


    @Override 
    protected void onCreate(Bundle savedInstanceState) { 
     super.onCreate(savedInstanceState); 
     setContentView(R.layout.activity_main); 


     if (googleMap == null) { 
      googleMap = ((MapFragment) getFragmentManager().findFragmentById(
        R.id.map)).getMap(); 

      // check if map is created successfully or not 
      if (googleMap == null) { 
       Toast.makeText(getApplicationContext(), 
         "Sorry! unable to create maps", Toast.LENGTH_SHORT) 
         .show(); 
      } 
     } 


    } 

    @Override 
    public boolean onCreateOptionsMenu(Menu menu) { 
     // Inflate the menu; this adds items to the action bar if it is present. 
     getMenuInflater().inflate(R.menu.main, menu); 
     return true; 
    } 

} 

activity_main.xml

<?xml version="1.0" encoding="utf-8"?> 
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="fill_parent" 
    android:layout_height="fill_parent" > 

    <fragment 
     android:id="@+id/map" 
     android:name="com.google.android.gms.maps.MapFragment" 
     android:layout_width="match_parent" 
     android:layout_height="match_parent"/> 

</RelativeLayout> 

AndroidManifest.xml

<?xml version="1.0" encoding="utf-8"?> 
<manifest xmlns:android="http://schemas.android.com/apk/res/android" 
    package="com.example.testmap" 
    android:versionCode="1" 
    android:versionName="1.0" > 

    <uses-sdk 
     android:minSdkVersion="14" 
     android:targetSdkVersion="17" /> 

    <uses-feature 
     android:glEsVersion="0x00020000" 
     android:required="true" /> 

    <uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" /> 
    <uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" /> 
    <uses-permission android:name="android.permission.INTERNET" /> 
    <uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" /> 
    <uses-permission android:name="android.permission.READ_INTERNAL_STORAGE" /> 
    <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" /> 
    <uses-permission android:name="com.google.android.providers.gsf.permission.READ_GSERVICES" /> 



    <application 
     android:allowBackup="true" 
     android:icon="@drawable/ic_launcher" 
     android:label="@string/app_name" 
     android:theme="@style/AppTheme" > 

     <meta-data 
      android:name="com.google.android.gms.version" 
      android:value="@integer/google_play_services_version" /> 
<!-- Required OpenGL ES 2.0. for Maps V2 --> 

     <activity 
      android:name="com.example.testmap.MainActivity" 
      android:label="@string/app_name" > 
      <intent-filter> 
       <action android:name="android.intent.action.MAIN" /> 

       <category android:name="android.intent.category.LAUNCHER" /> 
      </intent-filter> 
     </activity> 

     <!-- Goolge API Key --> 
     <meta-data 
      android:name="com.google.android.maps.v2.API_KEY" 
      android:value="AIzaSyAo7D5KmWcB8hdw6QZ_xxxxxxxxxxlv6m0" /> 
<!--add your api here as android:value --> 


    </application> 

</manifest> 
+0

Вы можете добавить трассировки стека исключений, а? – korrekorre

ответ

0

Вы не write с разрешения внешнего хранения поэтому добавьте

<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/> 

в ваших разрешениях

+1

Вы уверены, что ваш ответ решает проблему? –

+0

Этот ответ сработал для меня. Спасибо!! –

+0

К вашим услугам – M090009

0

Замените фрагмент тег со следующим

<fragment 
    android:id="@+id/map" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    class="com.google.android.gms.maps.SupportMapFragment"/> 

Насколько мне известно, MapFragment предназначен для более старых версий API.

+1

, но 'android: minSdkVersion =" 14 "' тогда это хорошо использовать 'MapFragment' –

+0

Я думаю, что MapFragment предназначен для собственного фрагмента фрагмента API API уровня 11. –

+0

Спасибо, что помогли мне! –