2

Android 2.3.3

I have read a lot of questions on the same issue, but the more I read the more I get confused. So, I am putting my problem here, please bear if its a duplicate, but I really can't figure it out.

I have minSdkVersion=8 and targetSdkVersion=17 and 
I am targeting devices from Android version 2.2 and above

Here is the list of things I have done :

  1. Signed up for Google API Console - Got API Key - Turned on Google Maps Android API V2.
  2. Imported google-play-services_lib into the project, added it as a library.
  3. Since I am targeting Versions below 3.0, I have read some where that I should be using ActionbarSherlock, So I imported that as well and added it as a library.

Please look at the screenshots and the code below and let me know, where I am going wrong. I have read that, I need to use "SupportMapFragment" in XML and "extend FragmentActivity" in the class file, but I am not getting it to work correctly.

enter image description here

enter image description here

AndroidManifest.XML

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

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

        <permission
            android:name="com.xx.xxx.permission.MAPS_RECEIVE"
            android:protectionLevel="signature" />

        <uses-feature
            android:glEsVersion="0x00020000"
            android:required="true" />

        <uses-permission android:name="com.xx.xxx.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" />


        <application
            android:name=".xxxApp"
            android:allowBackup="true"
            android:icon="@drawable/ic_launcher"
            android:label="@string/appName" >
            <uses-library android:name="com.google.android.maps" />

            <activity
                android:name=".SplashActivity"
                android:screenOrientation="portrait"
                android:theme="@android:style/Theme.Light.NoTitleBar.Fullscreen" >
                <intent-filter>
                    <action android:name="android.intent.action.MAIN" />

                    <category android:name="android.intent.category.LAUNCHER" />
                </intent-filter>
            </activity>

//All Activities are declared here, including the MapsActivity

            <!-- Google Maps APIV2  Key -->
            <meta-data
                android:name="com.google.android.maps.v2.API_KEY"
                android:value="My_API_KEY(Removed)" />

        </application>

    </manifest>

maps.xml

    <?xml version="1.0" encoding="utf-8"?>
    <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:orientation="vertical" >

        <RelativeLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content" >

            <ImageView
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:contentDescription="@string/imageDescription"
                android:scaleType="fitXY"
                android:src="@drawable/nav_bar_background" />

            <TextView
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_centerInParent="true"
                android:text="@string/map"
                android:textColor="#FFFFFF"
                android:textSize="20sp"
                android:textStyle="bold" />
        </RelativeLayout>

        <fragment
            android:id="@+id/map"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
//changed this to support versions < 3.0
            class="com.google.android.gms.maps.SupportMapFragment" />

    </LinearLayout>

MapsActivity.xml

    public class MapsActivity extends FragmentActivity {
        private MapView mapView;
        private GoogleAnalyticsTracker tracker;
        private GeoPoint point;
        private OverlayItem overlayitem;

        static final LatLng hacc_position = new LatLng(25.981343, -80.161756);
        //static final LatLng KIEL = new LatLng(53.551, 9.993);
        private GoogleMap map;

        @Override
        protected void onCreate(Bundle bundle) {
            super.onCreate(bundle);
            setContentView(R.layout.maps);

  **//Error at below line :  SupportMapFragment cannot be resolved**

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

            Marker hacc = map.addMarker(new MarkerOptions().position(hacc_position)
                    .title("XYZ"));

            // Move the camera instantly to hacc with a zoom of 15.
            map.moveCamera(CameraUpdateFactory.newLatLngZoom(hacc_position, 15));

            // Zoom in, animating the camera.
            map.animateCamera(CameraUpdateFactory.zoomTo(10), 2000, null);
            }

I am not sure on how to get this issue resolved. I have to support devices from Version 2.2 and above and thats mandatory.

Can someone please help.

I am not able to execute the project as I have error at

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

Let me know, if you need any info.

Problems Screenshot:

enter image description here

Thanks for the help!!!

As per suggestion of CommonsWare, I have imported the package and the error is gone. When I run the application, I get a ClassNotFoundException. Please have a look at the logcat trace.

06-26 17:27:15.759: E/Crittercism(19853): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.xx.xxx/com.xx.xxx.MapsActivity}: android.view.InflateException: Binary XML file line #28: Error inflating class fragment
06-26 17:27:15.759: E/Crittercism(19853):   at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1651)
06-26 17:27:15.759: E/Crittercism(19853):   at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1667)
06-26 17:27:15.759: E/Crittercism(19853):   at android.app.ActivityThread.access$1500(ActivityThread.java:117)
06-26 17:27:15.759: E/Crittercism(19853):   at android.app.ActivityThread$H.handleMessage(ActivityThread.java:935)
06-26 17:27:15.759: E/Crittercism(19853):   at android.os.Handler.dispatchMessage(Handler.java:99)
06-26 17:27:15.759: E/Crittercism(19853):   at android.os.Looper.loop(Looper.java:130)
06-26 17:27:15.759: E/Crittercism(19853):   at android.app.ActivityThread.main(ActivityThread.java:3687)
06-26 17:27:15.759: E/Crittercism(19853):   at java.lang.reflect.Method.invokeNative(Native Method)
06-26 17:27:15.759: E/Crittercism(19853):   at java.lang.reflect.Method.invoke(Method.java:507)
06-26 17:27:15.759: E/Crittercism(19853):   at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:878)
06-26 17:27:15.759: E/Crittercism(19853):   at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:636)
06-26 17:27:15.759: E/Crittercism(19853):   at dalvik.system.NativeStart.main(Native Method)
06-26 17:27:15.759: E/Crittercism(19853): Caused by: android.view.InflateException: Binary XML file line #28: Error inflating class fragment
06-26 17:27:15.759: E/Crittercism(19853):   at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:581)
06-26 17:27:15.759: E/Crittercism(19853):   at android.view.LayoutInflater.rInflate(LayoutInflater.java:623)
06-26 17:27:15.759: E/Crittercism(19853):   at android.view.LayoutInflater.inflate(LayoutInflater.java:408)
06-26 17:27:15.759: E/Crittercism(19853):   at android.view.LayoutInflater.inflate(LayoutInflater.java:320)
06-26 17:27:15.759: E/Crittercism(19853):   at android.view.LayoutInflater.inflate(LayoutInflater.java:276)
06-26 17:27:15.759: E/Crittercism(19853):   at com.android.internal.policy.impl.PhoneWindow.setContentView(PhoneWindow.java:207)
06-26 17:27:15.759: E/Crittercism(19853):   at android.app.Activity.setContentView(Activity.java:1657)
06-26 17:27:15.759: E/Crittercism(19853):   at com.waspmobile.haccoclc.MapsActivity.onCreate(MapsActivity.java:54)
06-26 17:27:15.759: E/Crittercism(19853):   at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047)
06-26 17:27:15.759: E/Crittercism(19853):   at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1615)
06-26 17:27:15.759: E/Crittercism(19853):   ... 11 more
06-26 17:27:15.759: E/Crittercism(19853): Caused by: java.lang.ClassNotFoundException: android.view.fragment in loader dalvik.system.PathClassLoader[/system/framework/com.google.android.maps.jar:/data/app/com.xx.xxx-1.apk]
06-26 17:27:15.759: E/Crittercism(19853):   at dalvik.system.PathClassLoader.findClass(PathClassLoader.java:240)
06-26 17:27:15.759: E/Crittercism(19853):   at java.lang.ClassLoader.loadClass(ClassLoader.java:551)
06-26 17:27:15.759: E/Crittercism(19853):   at java.lang.ClassLoader.loadClass(ClassLoader.java:511)
06-26 17:27:15.759: E/Crittercism(19853):   at android.view.LayoutInflater.createView(LayoutInflater.java:471)
06-26 17:27:15.759: E/Crittercism(19853):   at android.view.LayoutInflater.onCreateView(LayoutInflater.java:549)
06-26 17:27:15.759: E/Crittercism(19853):   at com.android.internal.policy.impl.PhoneLayoutInflater.onCreateView(PhoneLayoutInflater.java:66)
06-26 17:27:15.759: E/Crittercism(19853):   at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:568)
06-26 17:27:15.759: E/Crittercism(19853):   ... 20 more
06-26 17:27:15.959: E/AndroidRuntime(19853): FATAL EXCEPTION: main
06-26 17:27:15.959: E/AndroidRuntime(19853): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.xx.xxx/com.xx.xxx.MapsActivity}: android.view.InflateException: Binary XML file line #28: Error inflating class fragment
06-26 17:27:15.959: E/AndroidRuntime(19853):    at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1651)
06-26 17:27:15.959: E/AndroidRuntime(19853):    at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1667)
06-26 17:27:15.959: E/AndroidRuntime(19853):    at android.app.ActivityThread.access$1500(ActivityThread.java:117)
06-26 17:27:15.959: E/AndroidRuntime(19853):    at android.app.ActivityThread$H.handleMessage(ActivityThread.java:935)
06-26 17:27:15.959: E/AndroidRuntime(19853):    at android.os.Handler.dispatchMessage(Handler.java:99)
06-26 17:27:15.959: E/AndroidRuntime(19853):    at android.os.Looper.loop(Looper.java:130)
06-26 17:27:15.959: E/AndroidRuntime(19853):    at android.app.ActivityThread.main(ActivityThread.java:3687)
06-26 17:27:15.959: E/AndroidRuntime(19853):    at java.lang.reflect.Method.invokeNative(Native Method)
06-26 17:27:15.959: E/AndroidRuntime(19853):    at java.lang.reflect.Method.invoke(Method.java:507)
06-26 17:27:15.959: E/AndroidRuntime(19853):    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:878)
06-26 17:27:15.959: E/AndroidRuntime(19853):    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:636)
06-26 17:27:15.959: E/AndroidRuntime(19853):    at dalvik.system.NativeStart.main(Native Method)
06-26 17:27:15.959: E/AndroidRuntime(19853): Caused by: android.view.InflateException: Binary XML file line #28: Error inflating class fragment
06-26 17:27:15.959: E/AndroidRuntime(19853):    at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:581)
06-26 17:27:15.959: E/AndroidRuntime(19853):    at android.view.LayoutInflater.rInflate(LayoutInflater.java:623)
06-26 17:27:15.959: E/AndroidRuntime(19853):    at android.view.LayoutInflater.inflate(LayoutInflater.java:408)
06-26 17:27:15.959: E/AndroidRuntime(19853):    at android.view.LayoutInflater.inflate(LayoutInflater.java:320)
06-26 17:27:15.959: E/AndroidRuntime(19853):    at android.view.LayoutInflater.inflate(LayoutInflater.java:276)
06-26 17:27:15.959: E/AndroidRuntime(19853):    at com.android.internal.policy.impl.PhoneWindow.setContentView(PhoneWindow.java:207)
06-26 17:27:15.959: E/AndroidRuntime(19853):    at android.app.Activity.setContentView(Activity.java:1657)
06-26 17:27:15.959: E/AndroidRuntime(19853):    at com.xx.xxx.MapsActivity.onCreate(MapsActivity.java:54)
06-26 17:27:15.959: E/AndroidRuntime(19853):    at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047)
06-26 17:27:15.959: E/AndroidRuntime(19853):    at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1615)
06-26 17:27:15.959: E/AndroidRuntime(19853):    ... 11 more
06-26 17:27:15.959: E/AndroidRuntime(19853): Caused by: java.lang.ClassNotFoundException: android.view.fragment in loader dalvik.system.PathClassLoader[/system/framework/com.google.android.maps.jar:/data/app/com.xx.xxx-1.apk]
06-26 17:27:15.959: E/AndroidRuntime(19853):    at dalvik.system.PathClassLoader.findClass(PathClassLoader.java:240)
06-26 17:27:15.959: E/AndroidRuntime(19853):    at java.lang.ClassLoader.loadClass(ClassLoader.java:551)
06-26 17:27:15.959: E/AndroidRuntime(19853):    at java.lang.ClassLoader.loadClass(ClassLoader.java:511)
06-26 17:27:15.959: E/AndroidRuntime(19853):    at android.view.LayoutInflater.createView(LayoutInflater.java:471)
06-26 17:27:15.959: E/AndroidRuntime(19853):    at android.view.LayoutInflater.onCreateView(LayoutInflater.java:549)
06-26 17:27:15.959: E/AndroidRuntime(19853):    at com.android.internal.policy.impl.PhoneLayoutInflater.onCreateView(PhoneLayoutInflater.java:66)
06-26 17:27:15.959: E/AndroidRuntime(19853):    at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:568)
06-26 17:27:15.959: E/AndroidRuntime(19853):    ... 20 more

Order and Export tab

enter image description here

Vamsi Challa
  • 11,038
  • 31
  • 99
  • 149
  • Please paste the stack trace. – CommonsWare Jun 26 '13 at 11:47
  • @CommonsWare, I cannot run the application, as I have the error at the mentioned line above. Please have a look at it. – Vamsi Challa Jun 26 '13 at 11:49
  • Sorry about the title, I have changed the code, I will edit the title now. – Vamsi Challa Jun 26 '13 at 11:50
  • What are the issues displayed in `Problems` tab (`Windows > Show View > Problems`) – Krrishnaaaa Jun 26 '13 at 11:51
  • @Krrishnaaaa, I have updated the question with Problems screenshot, it says SupportMapFragment Cannot be resolved to a type – Vamsi Challa Jun 26 '13 at 11:54
  • [visit this link](http://stackoverflow.com/a/17106357/2194831) to solve ClassNotFoundException. BTW, CommonsWare have already suggested that. – Krrishnaaaa Jun 26 '13 at 12:09
  • @Krrishnaaaa, I have went to the link that you have given and I have updated the question with the screenshot of the order and export tab. I have the android private libraries checked. Can you have a look at it. – Vamsi Challa Jun 26 '13 at 12:20
  • In your `at com.xx.xxx.MapsActivity.onCreate(MapsActivity.java:54)` you have set a layout at line 54. In that layout check Line number 28. The View is not found. That's why its giving `ClassNotFoundException` – Krrishnaaaa Jun 26 '13 at 12:38

3 Answers3

9

Perhaps you are missing the import statement for com.google.android.gms.maps.SupportMapFragment.

You may also wish to confirm that, if you are on the R22 tools, that your "Order & Export" portion of the Eclipse build path dialog is properly configured.

Community
  • 1
  • 1
CommonsWare
  • 986,068
  • 189
  • 2,389
  • 2,491
  • You are right. I am missing the import. I added the import and ran the application. However, I get an few exceptions(ClassNotFoundException, I guess). I have updated the question with my logcat trace. Please have a look at it. – Vamsi Challa Jun 26 '13 at 12:05
  • Your exception is usually associated with an attempt to load a layout containing a `` from something other than a `FragmentActivity`, when using the Android Support package's backport of fragments. – CommonsWare Jun 26 '13 at 12:09
-1

I dont think so the below code would work

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

You should be using getChildFragmentManager(); to retrieve the fragment.

map = (SupportMapFragment)  getChildFragmentManager().findFragmentById(R.id.map);
blganesh101
  • 3,647
  • 1
  • 24
  • 44
-1

@Vamsi Challa I resolved your problem in my ECLIPSE IDE by impoting import com.google.android.gms.maps.MapFragment; and then changing

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

to

map = ((MapFragment) getFragmentManager().findFragmentById(R.id.map)).getMap();

And then it resolved the issue for me. PS --> MANIFEST IS USING: <uses-sdk android:minSdkVersion="8" android:targetSdkVersion="15" />

vivek
  • 356
  • 3
  • 7