2

I am having trouble getting this example working from the developers site and am stuck (probably with something simple) here is my xml layout

<?xml version="1.0" encoding="utf-8"?>
<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 
        android:id="@+id/map"
        class="com.google.android.gms.maps.MapFragment"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"/>
</RelativeLayout>

my main activity

    package PackageName.AndroidMapsTest;
    import android.os.Bundle;
    import android.app.Activity;

    public class MainActivity extends Activity {
        protected void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
            setContentView(R.layout.map_test_1);
        }
    }

and my manifest

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

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

    <permission
        android:name="Pakagename.AndroidMapsTest.permission.MAPS_RECIVE"
        android:protectionLevel="signature" />
        <uses-permission android:name="Pakagename.AndroidMapsTest.permission.MAPS_RECIVE"/>

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

    <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="edu.lewisu.cs.shanejmiller.AndroidMapsTest.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>

        <meta-data
            android:name="com.google.android.maps.v2.API_KEY"
            android:value="my_api_key" />

    </application>

</manifest>

And the error that i am getting from the log cat is

java.lang.RunTimeException: Unable to start activity ComponentInfo{packagename.AndroidMapsTest/packagename.AndroidMapsTest.MainActivity}: android.view.InflateException: Binary XML file line #8: Error inflating class fragment 

I have been stuck for a wile now and would appreciate any help. Thanks in advance

log trace

07-05 22:00:55.633: E/AndroidRuntime(1799): FATAL EXCEPTION: main
07-05 22:00:55.633: E/AndroidRuntime(1799): java.lang.RuntimeException: Unable to start activity ComponentInfo{edu.lewisu.cs.shanejmiller.AndroidMapsTest/edu.lewisu.cs.shanejmiller.AndroidMapsTest.MainActivity}: android.view.InflateException: Binary XML file line #8: Error inflating class fragment
07-05 22:00:55.633: E/AndroidRuntime(1799):     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2180)
07-05 22:00:55.633: E/AndroidRuntime(1799):     at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2230)
07-05 22:00:55.633: E/AndroidRuntime(1799):     at android.app.ActivityThread.access$600(ActivityThread.java:141)
07-05 22:00:55.633: E/AndroidRuntime(1799):     at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1234)
07-05 22:00:55.633: E/AndroidRuntime(1799):     at android.os.Handler.dispatchMessage(Handler.java:99)
07-05 22:00:55.633: E/AndroidRuntime(1799):     at android.os.Looper.loop(Looper.java:137)
07-05 22:00:55.633: E/AndroidRuntime(1799):     at android.app.ActivityThread.main(ActivityThread.java:5041)
07-05 22:00:55.633: E/AndroidRuntime(1799):     at java.lang.reflect.Method.invokeNative(Native Method)
07-05 22:00:55.633: E/AndroidRuntime(1799):     at java.lang.reflect.Method.invoke(Method.java:511)
07-05 22:00:55.633: E/AndroidRuntime(1799):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:793)
07-05 22:00:55.633: E/AndroidRuntime(1799):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:560)
07-05 22:00:55.633: E/AndroidRuntime(1799):     at dalvik.system.NativeStart.main(Native Method)
07-05 22:00:55.633: E/AndroidRuntime(1799): Caused by: android.view.InflateException: Binary XML file line #8: Error inflating class fragment
07-05 22:00:55.633: E/AndroidRuntime(1799):     at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:704)
07-05 22:00:55.633: E/AndroidRuntime(1799):     at android.view.LayoutInflater.rInflate(LayoutInflater.java:746)
07-05 22:00:55.633: E/AndroidRuntime(1799):     at android.view.LayoutInflater.inflate(LayoutInflater.java:489)
07-05 22:00:55.633: E/AndroidRuntime(1799):     at android.view.LayoutInflater.inflate(LayoutInflater.java:396)
07-05 22:00:55.633: E/AndroidRuntime(1799):     at android.view.LayoutInflater.inflate(LayoutInflater.java:352)
07-05 22:00:55.633: E/AndroidRuntime(1799):     at com.android.internal.policy.impl.PhoneWindow.setContentView(PhoneWindow.java:270)
07-05 22:00:55.633: E/AndroidRuntime(1799):     at android.app.Activity.setContentView(Activity.java:1881)
07-05 22:00:55.633: E/AndroidRuntime(1799):     at edu.lewisu.cs.shanejmiller.AndroidMapsTest.MainActivity.onCreate(MainActivity.java:15)
07-05 22:00:55.633: E/AndroidRuntime(1799):     at android.app.Activity.performCreate(Activity.java:5104)
07-05 22:00:55.633: E/AndroidRuntime(1799):     at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1080)
07-05 22:00:55.633: E/AndroidRuntime(1799):     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2144)
07-05 22:00:55.633: E/AndroidRuntime(1799):     ... 11 more
07-05 22:00:55.633: E/AndroidRuntime(1799): Caused by: android.app.Fragment$InstantiationException: Unable to instantiate fragment com.google.android.gms.maps.MapFragment: make sure class name exists, is public, and has an empty constructor that is public
07-05 22:00:55.633: E/AndroidRuntime(1799):     at android.app.Fragment.instantiate(Fragment.java:592)
07-05 22:00:55.633: E/AndroidRuntime(1799):     at android.app.Fragment.instantiate(Fragment.java:560)
07-05 22:00:55.633: E/AndroidRuntime(1799):     at android.app.Activity.onCreateView(Activity.java:4709)
07-05 22:00:55.633: E/AndroidRuntime(1799):     at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:680)
07-05 22:00:55.633: E/AndroidRuntime(1799):     ... 21 more
07-05 22:00:55.633: E/AndroidRuntime(1799): Caused by: java.lang.ClassNotFoundException: Didn't find class "com.google.android.gms.maps.MapFragment" on path: /data/app/edu.lewisu.cs.shanejmiller.AndroidMapsTest-2.apk
07-05 22:00:55.633: E/AndroidRuntime(1799):     at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:65)
07-05 22:00:55.633: E/AndroidRuntime(1799):     at java.lang.ClassLoader.loadClass(ClassLoader.java:501)
07-05 22:00:55.633: E/AndroidRuntime(1799):     at java.lang.ClassLoader.loadClass(ClassLoader.java:461)
07-05 22:00:55.633: E/AndroidRuntime(1799):     at android.app.Fragment.instantiate(Fragment.java:582)
07-05 22:00:55.633: E/AndroidRuntime(1799):     ... 24 more
4
  • 1
    Your class can extend standard activity public class MainActivity extends Activity { Commented Jul 5, 2013 at 19:57
  • even after changing it to Activity I still receive the logcat messages above Commented Jul 5, 2013 at 21:11
  • have you referenced google play library project in your android map project. Commented Jul 5, 2013 at 21:13
  • yes I have and I am using the 17 google api emulator too Commented Jul 5, 2013 at 21:58

3 Answers 3

4

You are trying to use com.google.android.gms.maps.MapFragment (for native API Level 11+ fragments) with FragmentActivity (for the Android Support backport of fragments). Those need to match. Since your android:minSdkVersion is 12, change FragmentActivity to Activity.

Sign up to request clarification or add additional context in comments.

6 Comments

Even after Replacing FragmentActivity to Activity I still receive th same error in my logcat
@ShaneMiller: Then please edit your question to post the entire stack trace.
@ShaneMiller: If you are on the R22 (or higher) tools, make sure that the "Order & Export" portion of your build path is set up properly: stackoverflow.com/questions/16596969/…
Yes I checked the Order & Export and it was ok. still receiving the same error messages
@ShaneMiller: Then something else is messed up in your project setup, as the APK does not contain the MapFragment class. Make sure that you correctly attached the Play Services SDK Android library project to your app (i.e., you didn't just add some JAR to your build path manually).
|
1

Try to add this into Manifest:

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

It works for me.

1 Comment

This is needed, true, but it's not the solution to the OP's problem at hand.
1
  <meta-data
        android:name="com.google.android.maps.v2.API_KEY"
        android:value=" your api key" />

below this include this also

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

and also change xml like this....

 <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent" >

<fragment
    android:id="@+id/map"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    class="com.google.android.gms.maps.SupportMapFragment" />

</RelativeLayout>

change activity to

 public class MainActivity extends FragmentActivity 

and initialization to.......

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

that should do it.

1 Comment

+1 just for those two extra lines in manifest. It is working for me with fragment.

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.