Reputation: 399
Hi i used google map v2 and if i run app
public class SocMap extends Activity {
}
open map but i if run app
public class SocMap extends FragmentActivity {
}
app crash
error:
04-28 15:10:03.405: E/AndroidRuntime(12041): FATAL EXCEPTION: main
04-28 15:10:03.405: E/AndroidRuntime(12041): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.socmap/com.example.socmap.SocMap}: android.view.InflateException: Binary XML file line #6: Error inflating class fragment
04-28 15:10:03.405: E/AndroidRuntime(12041): Caused by: android.view.InflateException: Binary XML file line #6: Error inflating class fragment
04-28 15:10:03.405: E/AndroidRuntime(12041): Caused by: java.lang.ClassCastException: com.google.android.gms.maps.MapFragment cannot be cast to android.support.v4.app.Fragment
Upvotes: 0
Views: 423
Reputation: 2143
Your error trace shows ClassCastException
java.lang.ClassCastException: com.google.android.gms.maps.MapFragment cannot be cast to android.support.v4.app.Fragment
It means You are using API less than 11 with FragmentActivity
and MapFragment
. Try to update API > 11 with Activity
and MapFragment
.
If you want to continue with API < 11 then use SupportMapFragment
instead of MapFragment
.
Refer this to implement MapFragment with API > 11 Google Map v2
Upvotes: 0
Reputation: 1355
Try this project you'll have all your answer regarding Google Map v2.
Android Working with Google Map V2
Upvotes: 0
Reputation: 3759
In your layout it looks like your using a MapFragment. Use android:name="com.google.android.gms.maps.SupportMapFragment"
instead and in your onCreate
, get the MapFragment like so:
SupportMapFragment mapFragment = (SupportMapFragment) getSupportFragmentManager().findFragmentById(R.id.mapFragment); //your SupportMapFragment's id will need to be set to this in your layout.
Upvotes: 0
Reputation: 1379
See my blog posts i have tried to summarize all there is needed to build an App with Google Maps API V2 for Android.
Upvotes: 0
Reputation: 41099
If you want to implement Google maps in your application and you want your application to target API < 11 then you will have to use the FragmentActivity
. FragmentActivity
is part of google-support-v4
library and basically gives you support for fragment for system prior to API level 11. in this case you would have to import this library. you can get an idea of how it's done by reading step 4 of this blog post I wrote on Google Maps integration:
You just have to remember that if this is the way you go you should use the SupportMapFragment
object for you map instead of the MapFragment
you are using currently.
If on the other hand you develop you app to API's level 11 and higher this step is not necessary and you simply can use a simple Activity
with a MapFragment
.
Upvotes: 1