-1

I am developing a simple Map. I'm new to this. i had developed using the tutorials provided by maps developing

My logcat error Looks like this

01-20 15:13:23.511: W/dalvikvm(28896): threadid=1: thread exiting with uncaught exception (group=0x417379a8)
01-20 15:13:23.520: E/AndroidRuntime(28896): FATAL EXCEPTION: main
01-20 15:13:23.520: E/AndroidRuntime(28896): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.nuappz.gotcha/com.nuappz.gotcha.MainActivity}: android.view.InflateException: Binary XML file line #2: Error inflating class fragment  
01-20 15:13:23.520: E/AndroidRuntime(28896):    at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2306)  
01-20 15:13:23.520: E/AndroidRuntime(28896):    at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2358)  
01-20 15:13:23.520: E/AndroidRuntime(28896):    at android.app.ActivityThread.access$600(ActivityThread.java:156)  
01-20 15:13:23.520: E/AndroidRuntime(28896):    at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1340)
01-20 15:13:23.520: E/AndroidRuntime(28896): Caused by: java.lang.IllegalStateException: A required meta-data tag in your app's AndroidManifest.xml does not exist.  You must have the following declaration within the <application> element:     <meta-data android:name="com.google.android.gms.version" android:value="@integer/google_play_services_version" />
01-20 15:13:23.520: E/AndroidRuntime(28896):    at com.google.android.gms.common.GooglePlayServicesUtil.n(Unknown Source)
01-20 15:13:23.520: E/AndroidRuntime(28896):    at com.google.android.gms.common.GooglePlayServicesUtil.isGooglePlayServicesAvailable(Unknown Source)
01-20 15:13:23.520: E/AndroidRuntime(28896):    at com.google.android.gms.maps.internal.q.v(Unknown Source)
01-20 15:13:23.520: E/AndroidRuntime(28896):    at com.google.android.gms.maps.internal.q.u(Unknown Source)
01-20 15:13:23.520: E/AndroidRuntime(28896):    at com.google.android.gms.maps.MapsInitializer.initialize(Unknown Source)
01-20 15:13:23.520: E/AndroidRuntime(28896):    at com.google.android.gms.maps.MapFragment$b.eb(Unknown Source)
01-20 15:13:23.520: E/AndroidRuntime(28896):    at com.google.android.gms.maps.MapFragment$b.a(Unknown Source)
01-20 15:13:23.520: E/AndroidRuntime(28896):    at com.google.android.gms.dynamic.a.a(Unknown Source)
01-20 15:13:23.520: E/AndroidRuntime(28896):    at com.google.android.gms.dynamic.a.onInflate(Unknown Source)
01-20 15:13:23.520: E/AndroidRuntime(28896):    at com.google.android.gms.maps.MapFragment.onInflate(Unknown Source)
01-20 15:13:23.520: E/AndroidRuntime(28896):    at android.app.Activity.onCreateView(Activity.java:4734)

And my code is

MainActivity.java

import android.app.Activity;
import android.os.Bundle;
import com.google.android.gms.maps.GoogleMap;
import com.google.android.gms.maps.MapFragment;

public class MainActivity extends Activity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        ((MapFragment) getFragmentManager().findFragmentById(R.id.map))
                .getMap();
    }
}  

AndroidManifest.xml

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

    <uses-sdk
        android:minSdkVersion="12"
        android:targetSdkVersion="19" />
    <permission
        android:name="com.nuappz.gotcha.android.locationapi.maps.permission.MAPS_RECEIVE"
        android:protectionLevel="signature" />
    <uses-permission android:name="com.nuappz.gotcha.android.locationapi.maps.permission.MAPS_RECEIVE" />
    <uses-permission android:name="android.permission.INTERNET" />
    <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
    <uses-permission android:name="com.google.android.providers.gsf.permission.READ_GSERVICES" />
    <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" >

        <activity
            android:name="com.nuappz.gotcha.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>

What is the problem here.

activity_main.xml

    <?xml version="1.0" encoding="utf-8"?>
    <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.MapFragment"/>

ImMathan
  • 3,911
  • 4
  • 29
  • 45

5 Answers5

0

There should be XML in the MainActivity.xml. The exception already says that it couldn't use the Layout:

android.view.InflateException: Binary XML file line #2: Error inflating class fragment
schlingel
  • 8,560
  • 7
  • 34
  • 62
0

Here your MainActivity must extends FragmentActivity

So Change

public class MainActivity extends FragmentActivity{
}
Jagadesh Seeram
  • 2,630
  • 1
  • 16
  • 29
0

The exception is quite self-explanatory when you read it:

A required meta-data tag in your app's AndroidManifest.xml does not exist.  You must have the following declaration within the <application> element:     <meta-data android:name="com.google.android.gms.version" android:value="@integer/google_play_services_version" />

So, add the following to your manifest application element:

<meta-data android:name="com.google.android.gms.version" android:value="@integer/google_play_services_version" />
laalto
  • 150,114
  • 66
  • 286
  • 303
0

Actually the problem is in the MainActivity.java file.
The MainActivity must extends to the FragmentActivity not Activity.
Because i am displaying map by the Fragment.

ImMathan
  • 3,911
  • 4
  • 29
  • 45
0

This is the particular problem i have faced few days ago .The problem is you are using the SHA1 KEY ,that is not meant for debugging,hence i suggest you not to get the key while exporting .

Vamsi Pavan Mahesh
  • 240
  • 1
  • 8
  • 30