0

I am following this tutorial , i used the original files provided in the tutorial but facing same problem.searched for many pre asked questions but could not find way to repair my error.I m having error of "Unfortunately app has stopped" I got errors in logcat as follow.

Logcat of my project

11-30 17:35:36.852: E/Trace(836): error opening trace file: No such file or directory (2)

11-30 17:35:37.432: D/AndroidRuntime(836): Shutting down VM

11-30 17:35:37.432: W/dalvikvm(836): threadid=1: thread exiting with uncaught exception 
(group=0x40a13300)

11-30 17:35:37.452: E/AndroidRuntime(836): FATAL EXCEPTION: main

11-30 17:35:37.452: E/AndroidRuntime(836): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.gmap/com.example.gmap.MainActivity}: android.view.InflateException: Binary XML file line #18: Error inflating class fragment

.java file as follows

    public class MainActivity extends FragmentActivity 
    implements OnMapClickListener {

private GoogleMap mMap;

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

    // Try to obtain the map from the SupportMapFragment.
    mMap = ((SupportMapFragment) getSupportFragmentManager().findFragmentById(R.id.map))
            .getMap();
    mMap.setOnMapClickListener(this);
}

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

@Override
public void onMapClick(LatLng position) {

    mMap.addMarker(new MarkerOptions()
                            .position(position)
                            .icon(BitmapDescriptorFactory.fromResource(R.drawable.ic_launcher)));

}

   }

Manifest file as follow

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

<uses-sdk
    android:minSdkVersion="13"
    android:targetSdkVersion="19" />

<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="com.google.android.providers.gsf.permission.READ_GSERVICES" />
<!-- External storage for caching. -->
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<!-- My Location -->
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />

<!-- Maps API needs OpenGL ES 2.0. -->
<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" >

    <!-- You must insert your own Google Maps for Android API v2 key in here. -->
    <meta-data
        android:name="com.google.android.maps.v2.API_KEY"
        android:value="I inserted key obtained" />

    <activity
        android:name="com.example.gmap.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>
Ahmad
  • 58,947
  • 17
  • 107
  • 133

1 Answers1

0

Your Java code seems to be correct. Try to remove the implements onClickListener and onClick method just for a try. Your manifest needs some changing. I suggest adding these elements:

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

<permission
    android:name="com.nurakanbpo.mygenie.permission.MAPS_RECEIVE"
    android:protectionLevel="signature" />

<uses-permission android:name="com.nurakanbpo.mygenie.MAPS_RECEIVE" />

Your minSdkVersion is 13 for which you dont need supportmapfragment. You can use mapfragment. Also since revision 13 of google play services was released you need to add this element to your you application tag:

<meta-data
        android:name="com.google.android.gms.version"
        android:value="@integer/google_play_services_version" />
Illegal Argument
  • 9,249
  • 2
  • 38
  • 56
  • Thanks it helped, I removed mMap.setOnMapClickListener(this);. . . Can you please tell me why this is not working – Muhammad Usman Nov 30 '13 at 15:02
  • As I told you your java code seems fine but have a look at this http://stackoverflow.com/questions/14013002/google-maps-android-api-v2-detect-touch-on-map – Illegal Argument Dec 01 '13 at 06:34