2

I just try to view a map on the display, but it does not work. I get an runtimeexception:

01-17 19:16:47.066: E/AndroidRuntime(6605): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.maptest/com.example.maptest.MainActivity}: android.view.InflateException: Binary XML file line #7: Error inflating class fragment

Java:

import com.google.android.gms.common.GooglePlayServicesUtil;
import com.google.android.gms.maps.GoogleMap;
import com.google.android.gms.maps.SupportMapFragment;
import com.google.android.gms.maps.MapFragment;
import com.google.android.maps.MapActivity;
import com.google.android.maps.MapView;
import android.os.Bundle;
import android.app.Activity;
import android.support.v4.app.FragmentActivity;
import android.support.v4.app.Fragment;




public class MainActivity extends FragmentActivity {
 getSupportFragmentManager().findFragmentById(R.id.map))

@Override
protected void onCreate(Bundle savedInstanceState) {
    GooglePlayServicesUtil.isGooglePlayServicesAvailable(getApplicationContext());

    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);


    SupportMapFragment fragment = new SupportMapFragment();
    getSupportFragmentManager().beginTransaction()
            .add(android.R.id.content, fragment).commit();

    setContentView(R.layout.activity_main);

    GooglePlayServicesUtil.isGooglePlayServicesAvailable(getApplicationContext());

    GoogleMap map = ((SupportMapFragment) 
 getSupportFragmentManager().findFragmentById(R.id.map)).getMap();
}


}

Manifest

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

<uses-sdk
    android:minSdkVersion="8"
            android:targetSdkVersion="16"/>
  <permission
      android:name="com.example.maptest.permission.MAPS_RECEIVE"
      android:protectionLevel="signature"/>
    <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="com.example.mapdemo.permission.MAPS_RECEIVE"/>


    <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="removed"/>


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

    </activity>
           <uses-library android:name="com.google.android.maps"/>
</application>

</manifest>

layout xml:

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context=".MainActivity" >

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

The key is v2 and i followed strict the google tutorial i found. I also imported android play services.

Could someone help me please? :)

1
  • in your oncreate Method setContentView(R.layout.activity_main); called two times Jan 17, 2013 at 19:36

1 Answer 1

3

I had a similar error when trying the Map API v2. However, I don't know whether it will help you.

My problem was that the google-play-services_lib had to be included as a library. In Eclipse, you can do this as follows:

  1. Use the Android SDK Manager to download the library.
  2. Create a new "Android Project from existing code" where you point to google-play-services_lib in the folder you used to install the SDK.
  3. Under "Project -> Properties -> Android" flag this project as "Is library".
  4. In your project, also open "Project -> Properties -> Android" and click on "Add" in the library section. Select the google-play-services_lib.

At least that worked for me.

4
  • mhm, I understand what u mean. But i have a problem: when i try to crate an project from an existing code and navigate to that projeckt, the project is showed, but in grey letters, so i cannot check it...do u know why that could be? Jan 17, 2013 at 20:18
  • I'm not sure what you mean. Can you provide a picture? However, I'm not an Eclipse expert and struggled with this issue for some hours...
    – Dan
    Jan 17, 2013 at 20:33
  • Sorry I cannot insert a picture, because i am a new user here. When I try to import the libary project into my workspace it tells me, that it is allready there, but I think it isnt Jan 17, 2013 at 20:48
  • he means this: img843.imageshack.us/img843/6970/stackoverflowquestion.png can you help?
    – Goku
    Jun 10, 2013 at 22:00

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.