0

I am new to android development , I have created a simple application to display Google map in my emulator but while running it is getting stopped without displaying map ..I need some assistance here I am giving my logcat below

01-24 06:03:10.304: E/AndroidRuntime(1427): FATAL EXCEPTION: main

01-24 06:03:10.304: E/AndroidRuntime(1427): java.lang.RuntimeException: Unable to start 

activity ComponentInfo{ca.sfu.cmpt276.bfraser/ca.sfu.cmpt276.bfraser.MainActivity}: 

android.view.InflateException: Binary XML file line #16: Error inflating class fragment

01-24 06:03:10.304: E/AndroidRuntime(1427):     at 

android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2180)

01-24 06:03:10.304: E/AndroidRuntime(1427):     at 

android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2230)

01-24 06:03:10.304: E/AndroidRuntime(1427):     at android.app.ActivityThread.access$600

(ActivityThread.java:141)

01-24 06:03:10.304: E/AndroidRuntime(1427):     at android.app.ActivityThread$H.handleMessage

(ActivityThread.java:1234)

my xml file and java class giving below

<TextView
    android:id="@+id/header"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:text="@string/hello_world" />
   <fragment 

      android:id="@+id/map"
      android:name="com.google.android.gms.maps.MapFragment"
      android:layout_below="@+id/header"
      android:layout_width="match_parent"
      android:layout_height="match_parent"

      />
    </RelativeLayout>

My Class-

package ca.sfu.cmpt276.bfraser;

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


     import android.os.Bundle;
      import android.app.Activity;
       import android.view.Menu;

       public class MainActivity extends Activity {

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

    GoogleMap map = ((MapFragment) 
        getFragmentManager().findFragmentById(R.id.map)).getMap();
    }

     @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;
     }

        }

android manifest file

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

       <uses-sdk
    android:minSdkVersion="11"
    android:targetSdkVersion="18" />
      <permission 
    android:name="ca.sfu.cmpt276.bfraser.permission.MAPS_RECEIVE"
    android:protectionLevel="signature">

         </permission>
      <uses-permission android:name="android.permission.INTERNET" />
         <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
      <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
        <uses-permission  
     android:name="com.google.android.providers.gsf.permission.READ_GSERVICES" />
      <!--
      The following two permissions are not required to use
       Google Maps Android API v2, but are recommended.
      -->
      <uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
        <uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
          <uses-feature 
       android:glEsVersion="0x00020000"
         android:required="true" />


         <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.maps.v2.API_KEY"
        android:value="My API Key"  />
         <activity
        android:name="ca.sfu.cmpt276.bfraser.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>
      </application>

      </manifest>
Shailendra Madda
  • 20,649
  • 15
  • 100
  • 138

4 Answers4

0

Add this extra meta-data in your manifest :

<meta-data
        android:name="com.google.android.gms.version"
        android:value="@integer/google_play_services_version" />
Vijju
  • 3,458
  • 1
  • 22
  • 20
0

If you want to run Google maps in emulator you need to follow this step by step procedure which I answered in previous question.

Community
  • 1
  • 1
Shailendra Madda
  • 20,649
  • 15
  • 100
  • 138
0

Your xml has a failure

use this code

<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">
</fragment>

and use android support library

Logi24
  • 528
  • 6
  • 17
0

Its is a silly mistake

You need to use FragmentActivity rather Activity here

replace this line

 public class MainActivity extends Activity

with

public class MainActivity extends FragmentActivity 

NOTE: To use map fragment you need to use "android-support-v13.jar" to use fragment with backword compatibility.

Biraj Zalavadia
  • 28,348
  • 10
  • 61
  • 77