1

I’ve been at this for a very, very long time(3 weeks) in Eclipse. Using the ‘Getting Started’ guide for google maps android api v2 I keep running into this issue. I’ve tried all the various ways of making this work from posts on SO in addition to following various tutorials online & on youtube and I still can’t get it to function. I’ve used Activity, FragmentActivity, , , adding name to fragment and there’s still an error inflating the class fragment.

Main error(topmost error in LogCat)

03-12 11:50:04.793: E/AndroidRuntime(9002): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.map2/com.example.map2.MainActivity}: android.view.InflateException: Binary XML file line #13: Error inflating class fragment

MainActivty.java (I’ve tried both Activity & FragmentActivity)

package com.example.map2;

import android.os.Bundle;
//import android.app.Activity;
import android.view.Menu;
import android.support.v4.app.FragmentActivity;

public class MainActivity extends FragmentActivity {

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


}

@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 (I’ve used both MapFragment & SupportMapFragment)

<?xml version="1.0" encoding="utf-8"?>
<fragment xmlns:android="http://schemas.android.com/apk/res/android"
       android:id="@+id/map"
    android:name="com.example.map2.MainActivity"
       android:layout_width="match_parent"
       android:layout_height="match_parent"
       class="com.google.android.gms.maps.SupportMapFragment"/>

Map2Manifest.xml

<?xml version="1.0" encoding="utf-8"?>

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

<permission
    android:name="com.example.map2.permission.MAPS_RECEIVE"
    android:protectionLevel="signature" />
<uses-permission android:name="com.example.map2.permission.MAPS_RECEIVE" />


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

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

screenshots of library settings, etc:

enter image description here

enter image description here

enter image description here

5
  • @FCo AFAIK that is not the problem its a child of application tag and that is right Commented Mar 13, 2014 at 17:12
  • @Raghunandan it is advised that you place it before the </application> closing tag at developers.google.com/maps/documentation/android/… . It has been a problem for other people before. Commented Mar 13, 2014 at 17:15
  • @FCo no it does not say so. it says before closing tag meaning child of application tag Commented Mar 13, 2014 at 17:15
  • @Raghunandan "In AndroidManifest.xml, add the following element as a child of the <application> element, by inserting it just before the closing tag </application>:" - step 1 of adding API key to your application. Personally caused a problem for me when I didn't have it in the right spot before. Commented Mar 13, 2014 at 17:17
  • @FCo that means to say as a child of application tag. try it yourself there should not be a problem Commented Mar 13, 2014 at 17:17

4 Answers 4

2

You have

android:minSdkVersion="13"

So you need to use MapFragment and extend Activity.

Change this

class="com.google.android.gms.maps.SupportMapFragment"/>

to

class="com.google.android.gms.maps.MapFragment"/>

And change this

public class MainActivity extends FragmentActivity {

to

public class MainActivity extends Activity {

ALso misisng a metag as a child of application tag

<meta-data
android:name="com.google.android.gms.version"
android:value="@integer/google_play_services_version" />
Sign up to request clarification or add additional context in comments.

8 Comments

So I made your changes and moved the meta data before the </application> like others stated. I get the 'Unable to execute dex: java heap space' prompt.(I've done all of the suggestions on increasing maxpermsize, xms, etc in eclipse.ini file). My log cat usually lists errors at this point, but right now its not showing anything.
@KFP this has nothing to do with your code. Also as a child of </application> tag means before the tag closes. what you had was right. Nothing wrong in having at the start. Its just before close of the tag. If you have it at the start also its a child of application tag. As far as the problem you say in the comment has nothing to do with the code
Also:I can't step through or even terminate a program once its ran. The eclipse I'm using(22.3.0) has all of those commands greyed out. My green arrow always shows that the app is still running. I've posted this issue on SO as well, but as of now no solution. Yet another bug i guess.
@KFP you need to test it on a real device. You can't create avd was the bug filed will fixed in next uild
I'm am using a real device. If I uncheck Android Private libraries in Java Build path(to resolve java heap space error) it gets past that and attempt to run on device but fails and I get "error inflating class fragment.
|
0

This: <meta-data android:name="com.google.android.maps.v2.API_KEY" android:value="#" /> should be just before this: </application> This may not fix your problem but it could cause another one later.

Also, if that's your entire manifest file, then you're missing another <meta-data>: <meta-data android:name="com.google.android.gms.version" android:value="@integer/google_play_services_version" />

Comments

0

I follow the Google Maps Android API V2 tutorial and I have the same code like you. I got this problems and I have solved it.
If you want to create the Google Map in android api < 11, you should keep your activity and your layout. You must add the add on your android Android Manifest file.

< meta-data
android:name="com.google.android.gms.version"
android:value="@integer/google_play_services_version" />

Here is my Android Manifest file

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

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

    <permission
        android:name="com.example.demogooglemap.permision.MAPS_RECEIVE"
        android:protectionLevel="signature" />

    <uses-permission android:name="com.example.demogooglemap.permision.MAPS_RECEIVE" />
    <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" />
    <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.gms.version"
            android:value="@integer/google_play_services_version" />
        <meta-data
            android:name="com.google.android.maps.v2.API_KEY"
            android:value="AIzaSyCpDUn3K-IJJxqTmR4qIsNHGgNdqF7YmV0" />

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

Hope this help.

Comments

0

Hope someone will find it useful. I encountered the same issue and tried a number of fixes , but nothing worked.I solved it as following. 1) I am using Android 2.1.2. 2) I created fragment using the automatic fragment creation method as shown in this screen shot. 3) Every time I run the program i get the same error.

->Solution

  • I created the java class and XML fie for my fragment separately.as following. Java Class Screenshot.

    Similarly I created a new layout file for the fragment.

And did the following in my newly created java class.

package com.example.shaoorjan.fragmentxml;

  import android.app.Fragment;
  import android.os.Bundle;
  import android.support.annotation.Nullable;
  import android.view.LayoutInflater;
  import android.view.View;
  import android.view.ViewGroup;


   public class BlankFragment extends Fragment {

@Nullable
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,      Bundle savedInstanceState) {
    return inflater.inflate(R.layout.fragment_blank,container,false);
}
 }

It worked all right.

Comments

Your Answer

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

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.