1

I have created Google Maps v2 app. I followed the tutorial step by step. And when I'm launching this app.

It show pop up "Unfortunately, Google Maps v2 has stopped".

Here is the logcat...

09-03 04:51:33.296: E/AndroidRuntime(2148): FATAL EXCEPTION: main
09-03 04:51:33.296: E/AndroidRuntime(2148): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.achson.googlemapsv2/com.achson.googlemapsv2.MainActivity}: android.view.InflateException: Binary XML file line #6: Error inflating class fragment
09-03 04:51:33.296: E/AndroidRuntime(2148):     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2211)
09-03 04:51:33.296: E/AndroidRuntime(2148):     at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2261)
09-03 04:51:33.296: E/AndroidRuntime(2148):     at android.app.ActivityThread.access$600(ActivityThread.java:141)
09-03 04:51:33.296: E/AndroidRuntime(2148):     at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1256)
09-03 04:51:33.296: E/AndroidRuntime(2148):     at android.os.Handler.dispatchMessage(Handler.java:99)
09-03 04:51:33.296: E/AndroidRuntime(2148):     at android.os.Looper.loop(Looper.java:137)
09-03 04:51:33.296: E/AndroidRuntime(2148):     at android.app.ActivityThread.main(ActivityThread.java:5103)
09-03 04:51:33.296: E/AndroidRuntime(2148):     at java.lang.reflect.Method.invokeNative(Native Method)
09-03 04:51:33.296: E/AndroidRuntime(2148):     at java.lang.reflect.Method.invoke(Method.java:525)
09-03 04:51:33.296: E/AndroidRuntime(2148):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:737)
09-03 04:51:33.296: E/AndroidRuntime(2148):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:553)
09-03 04:51:33.296: E/AndroidRuntime(2148):     at dalvik.system.NativeStart.main(Native Method)
09-03 04:51:33.296: E/AndroidRuntime(2148): Caused by: android.view.InflateException: Binary XML file line #6: Error inflating class fragment
09-03 04:51:33.296: E/AndroidRuntime(2148):     at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:713)
09-03 04:51:33.296: E/AndroidRuntime(2148):     at android.view.LayoutInflater.rInflate(LayoutInflater.java:755)
09-03 04:51:33.296: E/AndroidRuntime(2148):     at android.view.LayoutInflater.inflate(LayoutInflater.java:492)
09-03 04:51:33.296: E/AndroidRuntime(2148):     at android.view.LayoutInflater.inflate(LayoutInflater.java:397)
09-03 04:51:33.296: E/AndroidRuntime(2148):     at android.view.LayoutInflater.inflate(LayoutInflater.java:353)
09-03 04:51:33.296: E/AndroidRuntime(2148):     at com.android.internal.policy.impl.PhoneWindow.setContentView(PhoneWindow.java:267)
09-03 04:51:33.296: E/AndroidRuntime(2148):     at android.app.Activity.setContentView(Activity.java:1895)
09-03 04:51:33.296: E/AndroidRuntime(2148):     at com.achson.googlemapsv2.MainActivity.onCreate(MainActivity.java:18)
09-03 04:51:33.296: E/AndroidRuntime(2148):     at android.app.Activity.performCreate(Activity.java:5133)
09-03 04:51:33.296: E/AndroidRuntime(2148):     at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1087)
09-03 04:51:33.296: E/AndroidRuntime(2148):     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2175)
09-03 04:51:33.296: E/AndroidRuntime(2148):     ... 11 more
09-03 04:51:33.296: E/AndroidRuntime(2148): Caused by: java.lang.ClassCastException: com.google.android.gms.maps.SupportMapFragment cannot be cast to android.app.Fragment
09-03 04:51:33.296: E/AndroidRuntime(2148):     at android.app.Fragment.instantiate(Fragment.java:585)
09-03 04:51:33.296: E/AndroidRuntime(2148):     at android.app.Fragment.instantiate(Fragment.java:560)
09-03 04:51:33.296: E/AndroidRuntime(2148):     at android.app.Activity.onCreateView(Activity.java:4738)
09-03 04:51:33.296: E/AndroidRuntime(2148):     at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:689)
09-03 04:51:33.296: E/AndroidRuntime(2148):     ... 21 more

I assume that google-play-services isn't inside of Android Dependencies folder.

But it's inside of Android Private Libraries folder. I don't know how to import to Android Dependencies folder. Anyone who knows ? Please share at this.

09-06 15:29:30.480: E/AndroidRuntime(1260): FATAL EXCEPTION: main
09-06 15:29:30.480: E/AndroidRuntime(1260): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.googlemapsv2/com.example.googlemapsv2.MainActivity}: java.lang.NullPointerException: CameraUpdateFactory is not initialized
09-06 15:29:30.480: E/AndroidRuntime(1260):     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2180)
09-06 15:29:30.480: E/AndroidRuntime(1260):     at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2230)
09-06 15:29:30.480: E/AndroidRuntime(1260):     at android.app.ActivityThread.access$600(ActivityThread.java:141)
09-06 15:29:30.480: E/AndroidRuntime(1260):     at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1234)
09-06 15:29:30.480: E/AndroidRuntime(1260):     at android.os.Handler.dispatchMessage(Handler.java:99)
09-06 15:29:30.480: E/AndroidRuntime(1260):     at android.os.Looper.loop(Looper.java:137)
09-06 15:29:30.480: E/AndroidRuntime(1260):     at android.app.ActivityThread.main(ActivityThread.java:5041)
09-06 15:29:30.480: E/AndroidRuntime(1260):     at java.lang.reflect.Method.invokeNative(Native Method)
09-06 15:29:30.480: E/AndroidRuntime(1260):     at java.lang.reflect.Method.invoke(Method.java:511)
09-06 15:29:30.480: E/AndroidRuntime(1260):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:793)
09-06 15:29:30.480: E/AndroidRuntime(1260):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:560)
09-06 15:29:30.480: E/AndroidRuntime(1260):     at dalvik.system.NativeStart.main(Native Method)
09-06 15:29:30.480: E/AndroidRuntime(1260): Caused by: java.lang.NullPointerException: CameraUpdateFactory is not initialized
09-06 15:29:30.480: E/AndroidRuntime(1260):     at com.google.android.gms.internal.ac.a(Unknown Source)
09-06 15:29:30.480: E/AndroidRuntime(1260):     at com.google.android.gms.maps.CameraUpdateFactory.aV(Unknown Source)
09-06 15:29:30.480: E/AndroidRuntime(1260):     at com.google.android.gms.maps.CameraUpdateFactory.newLatLngZoom(Unknown Source)
09-06 15:29:30.480: E/AndroidRuntime(1260):     at com.example.googlemapsv2.MainActivity.onCreate(MainActivity.java:24)
09-06 15:29:30.480: E/AndroidRuntime(1260):     at android.app.Activity.performCreate(Activity.java:5104)
09-06 15:29:30.480: E/AndroidRuntime(1260):     at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1080)
09-06 15:29:30.480: E/AndroidRuntime(1260):     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2144)
09-06 15:29:30.480: E/AndroidRuntime(1260):     ... 11 more
achson
  • 13
  • 6
  • check ur manifest file ...see if the activity name is mentioned – D'yer Mak'er Sep 03 '13 at 08:59
  • check this http://stackoverflow.com/questions/17611017/importing-google-play-service-library-showing-a-red-x-next-to-this-reference-and/17611095#17611095. how to import the google play services library project. Are you adding it as a jar to your libs folder? You need to reference the library project in your map project. – Raghunandan Sep 03 '13 at 09:05
  • see this http://twntee.tumblr.com/post/59576020346/the-maps-api-adding-a-map-to-your-android-project – Rachit Mishra Sep 03 '13 at 09:06
  • There are a number of reasons (and fixes) why this can occur at this thread: http://stackoverflow.com/questions/13726189/android-google-maps-api-v2-supportmapfragment-errors – pfairbairn Sep 03 '13 at 09:07
  • also the error is because you are inflating the wrong fragment type – Rachit Mishra Sep 03 '13 at 09:07
  • check this http://stackoverflow.com/questions/14082851/error-inflating-class-fragment-with-google-map?rq=1 – Amol Sawant Sep 03 '13 at 09:09

3 Answers3

0

Have you declared the Activity in your manifest?

Edit: Once you import library into your workspace (In Eclipse), you right click on the project, open properties, click android and at the bottom you will see library import section. Add it to that.

KickAss
  • 4,210
  • 8
  • 33
  • 41
  • There's something wrong with google-play-service. It doesn't inside of Android Dependencies. Is it the problem ? – achson Sep 03 '13 at 09:14
  • Have your checked your manifest first? The problem is definitely there. I don't think you declared the Activity(s) – KickAss Sep 03 '13 at 09:18
  • I suppose not. It's hard to help when he doesn't post code or reply lol ;) – KickAss Sep 03 '13 at 09:37
  • 1
    sorry @KickAss i'm trying to solve too.. thanks for your help. :D the problem had solved. but it has another problems. :( – achson Sep 03 '13 at 10:41
0

What version of API are you using? How does look your xml with the map layout? I had the same problem recently. And it was caused because I was using wrong fragment type.

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

It worked when I put android:name="com.google.android.gms.maps.SupportMapFragment"

then in your code if you work with map you must extend FragmentActivity insetad of Activity for your class (public class MapActivity extends FragmentActivity)

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

And that is how you get the mapFragment in the code.

pajus_cz
  • 1,261
  • 1
  • 13
  • 19
0

Assuming a layout inflation error

Primarily caused by inflation of wrong fragment type based on imports.

Case 1: If you are using a MapFragment in your FragmentActivity or Activity, using the import android.support.v4.app.*(i.e. Your class extends the Activity or Fragment Activity from the this package), then you will get ClassCastException

Solution Use a SupportMapFragment

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

then use the code to get the map in your Activity.

SupportMapFragment mapFragment = ((SupportMapFragment) this
                        .getSupportFragmentManager().findFragmentById(R.id.map));

Case 2: If you are using a SupportMapfragment in your FragmentActivity or Activity ,using the import android.app.* (i.e. Your class extends the Activity or Fragment Activity from the this package), then also you will get ClassCastException

Solution: Use a MapFragment

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

then use in the code to get the map reference in your Acitivity

MapFragment mapFragment = ((MapFragment) this
                            .getSupportFragmentManager().findFragmentById(R.id.map));

Also, the play services need not to be specifically in the Android Dependencies folders, as Android Private folder is too added to your build path.

Rachit Mishra
  • 6,101
  • 4
  • 30
  • 51
  • i'm not using SupportMapFragment. i'm using MapFragment. googleMap = ((MapFragment) getFragmentManager().findFragmentById( R.id.map)).getMap(); – achson Sep 03 '13 at 10:03
  • i've changed. it was launching. but there is no google maps. it just empty on fragment. – achson Sep 03 '13 at 10:27
  • yup. but when i changed to another type of emulator. it displayed button label "Update". It said that google play service must be updated.. blablabla. – achson Sep 03 '13 at 10:41
  • http://twntee.tumblr.com/post/59576020346/the-maps-api-adding-a-map-to-your-android-project see the blog post, I have written about how to run it on emulator, your emulator/devices needs to have latest play services, install them via adb – Rachit Mishra Sep 03 '13 at 10:45
  • yup.. here the logcat said : "error opening trace file: No such file or directory (2)" – achson Sep 05 '13 at 04:14
  • @achson that's not an error, actually that is cause of mounted sd card to th emulator – Rachit Mishra Sep 05 '13 at 12:01
  • how many size to be needed ? I try 500 Mb. It didn't run too. – achson Sep 06 '13 at 06:26
  • no.. i mean that error is irrelevent to us with maps not showing up, see if there is any other error, like authentication error because of the api-key, edit yur question and post the new stack trace – Rachit Mishra Sep 06 '13 at 06:29
  • So, should I don't need sd card ? I've posted it above. – achson Sep 06 '13 at 09:32
  • @achson see the new error is due to un intitialisation of CameraUpdate Factory variable – Rachit Mishra Sep 06 '13 at 10:37