0

I am working on Map view using android API v2, I am following this tutorial, I have followed what he explained in tutorial, but still I am getting Fatal exception. here is my xml code with log cat.

<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"
    android:paddingBottom="@dimen/activity_vertical_margin"
    android:paddingLeft="@dimen/activity_horizontal_margin"
    android:paddingRight="@dimen/activity_horizontal_margin"
    android:paddingTop="@dimen/activity_vertical_margin"
    tools:context=".MainActivity" >

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

</RelativeLayout>

logcat:

05-08 10:38:22.121: E/AndroidRuntime(954): FATAL EXCEPTION: main
05-08 10:38:22.121: E/AndroidRuntime(954): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.map/com.example.map.MainActivity}: android.view.InflateException: Binary XML file line #11: Error inflating class fragment
05-08 10:38:22.121: E/AndroidRuntime(954):  at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2180)
05-08 10:38:22.121: E/AndroidRuntime(954):  at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2230)
05-08 10:38:22.121: E/AndroidRuntime(954):  at android.app.ActivityThread.access$600(ActivityThread.java:141)
05-08 10:38:22.121: E/AndroidRuntime(954):  at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1234)
05-08 10:38:22.121: E/AndroidRuntime(954):  at android.os.Handler.dispatchMessage(Handler.java:99)
05-08 10:38:22.121: E/AndroidRuntime(954):  at android.os.Looper.loop(Looper.java:137)
05-08 10:38:22.121: E/AndroidRuntime(954):  at android.app.ActivityThread.main(ActivityThread.java:5041)
05-08 10:38:22.121: E/AndroidRuntime(954):  at java.lang.reflect.Method.invokeNative(Native Method)
05-08 10:38:22.121: E/AndroidRuntime(954):  at java.lang.reflect.Method.invoke(Method.java:511)
05-08 10:38:22.121: E/AndroidRuntime(954):  at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:793)
05-08 10:38:22.121: E/AndroidRuntime(954):  at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:560)
05-08 10:38:22.121: E/AndroidRuntime(954):  at dalvik.system.NativeStart.main(Native Method)
05-08 10:38:22.121: E/AndroidRuntime(954): Caused by: android.view.InflateException: Binary XML file line #11: Error inflating class fragment
05-08 10:38:22.121: E/AndroidRuntime(954):  at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:704)
05-08 10:38:22.121: E/AndroidRuntime(954):  at android.view.LayoutInflater.rInflate(LayoutInflater.java:746)
05-08 10:38:22.121: E/AndroidRuntime(954):  at android.view.LayoutInflater.inflate(LayoutInflater.java:489)
05-08 10:38:22.121: E/AndroidRuntime(954):  at android.view.LayoutInflater.inflate(LayoutInflater.java:396)
05-08 10:38:22.121: E/AndroidRuntime(954):  at android.view.LayoutInflater.inflate(LayoutInflater.java:352)
05-08 10:38:22.121: E/AndroidRuntime(954):  at com.android.internal.policy.impl.PhoneWindow.setContentView(PhoneWindow.java:270)
05-08 10:38:22.121: E/AndroidRuntime(954):  at android.app.Activity.setContentView(Activity.java:1881)
05-08 10:38:22.121: E/AndroidRuntime(954):  at com.example.map.MainActivity.onCreate(MainActivity.java:12)
05-08 10:38:22.121: E/AndroidRuntime(954):  at android.app.Activity.performCreate(Activity.java:5104)
05-08 10:38:22.121: E/AndroidRuntime(954):  at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1080)
05-08 10:38:22.121: E/AndroidRuntime(954):  at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2144)
05-08 10:38:22.121: E/AndroidRuntime(954):  ... 11 more
05-08 10:38:22.121: E/AndroidRuntime(954): 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
05-08 10:38:22.121: E/AndroidRuntime(954):  at android.app.Fragment.instantiate(Fragment.java:592)
05-08 10:38:22.121: E/AndroidRuntime(954):  at android.app.Fragment.instantiate(Fragment.java:560)
05-08 10:38:22.121: E/AndroidRuntime(954):  at android.app.Activity.onCreateView(Activity.java:4709)
05-08 10:38:22.121: E/AndroidRuntime(954):  at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:680)
05-08 10:38:22.121: E/AndroidRuntime(954):  ... 21 more
05-08 10:38:22.121: E/AndroidRuntime(954): Caused by: java.lang.ClassNotFoundException: Didn't find class "com.google.android.gms.maps.MapFragment" on path: /data/app/com.example.map-2.apk
05-08 10:38:22.121: E/AndroidRuntime(954):  at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:65)
05-08 10:38:22.121: E/AndroidRuntime(954):  at java.lang.ClassLoader.loadClass(ClassLoader.java:501)
05-08 10:38:22.121: E/AndroidRuntime(954):  at java.lang.ClassLoader.loadClass(ClassLoader.java:461)
05-08 10:38:22.121: E/AndroidRuntime(954):  at android.app.Fragment.instantiate(Fragment.java:582)
05-08 10:38:22.121: E/AndroidRuntime(954):  ... 24 more

And my manifest is looks like this.

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

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

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

    <uses-feature
        android:glEsVersion="0x00020000"
        android:required="true" />
    <uses-permission android:name="com.example.map.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:allowBackup="true"
        android:icon="@drawable/ic_launcher"
        android:label="@string/app_name"
        android:theme="@style/AppTheme" >
        <activity
            android:name="com.example.map.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="AIzaSyDSW0CfwDN0LyrF8PBeihEjrAkj25TDhUQ" />
    </application>

</manifest>
Android learner
  • 1,871
  • 4
  • 24
  • 36

6 Answers6

1

Make sure that you are using Google APIs in the project build target. Go to project Properties > Android to check this.

Shashika
  • 1,151
  • 1
  • 9
  • 21
  • In my project Properties > Android their is no libraries, but i installed google-play-services. – Android learner May 08 '13 at 11:37
  • 1
    You should install Google APIs. Follow steps 1 and 2 of this link. http://shashikawlp.wordpress.com/2012/09/19/google-maps-tutorial-for-android/ – Shashika May 08 '13 at 15:46
1

You are trying to import existing project into library. You should be importing the library using following method.

  1. Right click package explorer. Import -> Expand Android -> Existing Android Code Into Workspace.
  2. Select the google-play-services library. And check the copy to workspace checkbox.

Once this is done. Reference the library project

Right click on the project. Select Android in the left pane. In the right pane bottom you would see a frame with label Library. Click on add and add the imported library.

To add support library to your project: Right click on the project Androids Tools -> Add Support library.

If you decide to use support libraries you will have to replace the code

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

with

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

also in your java file you will have to use SupportMapFragment.

mMap = ((SupportMapFragment) getSupportFragmentManager()
                    .findFragmentById(R.id.map)).getMap();
Anirudha Agashe
  • 3,510
  • 2
  • 32
  • 47
0

Are you using the correct API (GOOGLE API) in Eclipse? Make sure to use the GOOGLE APIs if you want to use google maps in android!

Widerberg
  • 1,118
  • 1
  • 10
  • 24
0

You are probably having an import problem. Just check in right click on project -> properties -> Java build path you have imported the libs. See this link for clarity

Community
  • 1
  • 1
CRUSADER
  • 5,486
  • 3
  • 28
  • 64
0

This error is usually derived from incorrect referencing of google-play-services library.

To do it correctly please follow the first 3 steps of this blog post guide I wrote on integrating Google Maps API V2 in your application:

Google Maps API V2

Emil Adz
  • 40,709
  • 36
  • 140
  • 187
  • I have seen my google-play-services By importing, like explained in your link as a second step. but their is no project of maps. – Android learner May 08 '13 at 11:34
  • what do you mean by: but their is no project of maps? – Emil Adz May 08 '13 at 11:35
  • When I tried to import lib, sdk\extras\google\google_play_services\libproject\google-play-services_lib here, then I got message No projects are found to import. – Android learner May 08 '13 at 11:41
  • So this is your problem. try to download/re-download the google-play-service package using the SDK Manager and perform this step again. without it your application won't work – Emil Adz May 08 '13 at 11:44
  • But I installed trough SDK Manager couple of times but still its not showing, any solution for this??? – Android learner May 08 '13 at 11:51
  • you can try to go here: http://venomvendor.blogspot.co.il/2012/03/android-sdk-extras-by-google-inc.html and download it manually. – Emil Adz May 08 '13 at 11:57
0
""Caused by: java.lang.ClassNotFoundException: Didn't find class"com.google.android.gms.maps.MapFragment" on path: /data/app/com.example.map-2.apk""

Have you checked this?

I think you should Add this (com.google.android.gms.maps.MapFragment)ACTIVITY in your AndroidManifest.XML.

Give a try to the three "caused by..." errors in the LogCat.

sai
  • 548
  • 10
  • 30
  • then you should seriously research on this!! " android.view.InflateException: Binary XML file line #11: Error inflating class fragment" – sai May 08 '13 at 11:40
  • Also try : 1.) Adding -> 2) extend your activity from "MapActivity" instead of Activity. – sai May 08 '13 at 11:40
  • Also I observed you are using "minSdkVersion="8" ". For that try to add android support files for fragments like "android.support.v4.app" and not "android.app.Fragment" – sai May 08 '13 at 11:43
  • I added in manifest, but got this error, Installation error: INSTALL_FAILED_MISSING_SHARED_LIBRARY – Android learner May 08 '13 at 11:47
  • Are you testing on device or emulator. – sai May 08 '13 at 11:54
  • 1
    Ok Folk That's it , You just thoroughly Go through "https://developers.google.com/maps/documentation/android/#avdsetup" this site. – sai May 08 '13 at 12:11