1

I am trying to create a layout with a MapView in it along with other items when I try to create a fragment to hold the view it crashes saying it cannot find the class (yes I did import the google play services library)

error:

03-08 13:48:01.593: E/AndroidRuntime(30614): android.view.InflateException: Binary XML file line #7: Error inflating class com.google.android.gms.maps.MapView
03-08 13:48:01.593: E/AndroidRuntime(30614):    at android.view.LayoutInflater.createView(LayoutInflater.java:613)
03-08 13:48:01.593: E/AndroidRuntime(30614):    at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:687)
03-08 13:48:01.593: E/AndroidRuntime(30614):    at android.view.LayoutInflater.rInflate(LayoutInflater.java:746)
03-08 13:48:01.593: E/AndroidRuntime(30614):    at android.view.LayoutInflater.inflate(LayoutInflater.java:489)
03-08 13:48:01.593: E/AndroidRuntime(30614):    at android.view.LayoutInflater.inflate(LayoutInflater.java:396)
03-08 13:48:01.593: E/AndroidRuntime(30614):    at com.ecm2.mobilemap.fragments.CurrentIncidentMapFrag.onCreateView(CurrentIncidentMapFrag.java:16)
03-08 13:48:01.593: E/AndroidRuntime(30614):    at android.app.Fragment.performCreateView(Fragment.java:1695)
03-08 13:48:01.593: E/AndroidRuntime(30614):    at android.app.FragmentManagerImpl.moveToState(FragmentManager.java:885)
03-08 13:48:01.593: E/AndroidRuntime(30614):    at android.app.FragmentManagerImpl.moveToState(FragmentManager.java:1057)
03-08 13:48:01.593: E/AndroidRuntime(30614):    at android.app.BackStackRecord.run(BackStackRecord.java:682)
03-08 13:48:01.593: E/AndroidRuntime(30614):    at android.app.FragmentManagerImpl.execPendingActions(FragmentManager.java:1435)
03-08 13:48:01.593: E/AndroidRuntime(30614):    at android.app.FragmentManagerImpl$1.run(FragmentManager.java:441)
03-08 13:48:01.593: E/AndroidRuntime(30614):    at android.os.Handler.handleCallback(Handler.java:725)
03-08 13:48:01.593: E/AndroidRuntime(30614):    at android.os.Handler.dispatchMessage(Handler.java:92)
03-08 13:48:01.593: E/AndroidRuntime(30614):    at android.os.Looper.loop(Looper.java:137)
03-08 13:48:01.593: E/AndroidRuntime(30614):    at android.app.ActivityThread.main(ActivityThread.java:5041)
03-08 13:48:01.593: E/AndroidRuntime(30614):    at java.lang.reflect.Method.invokeNative(Native Method)
03-08 13:48:01.593: E/AndroidRuntime(30614):    at java.lang.reflect.Method.invoke(Method.java:511)
03-08 13:48:01.593: E/AndroidRuntime(30614):    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:793)
03-08 13:48:01.593: E/AndroidRuntime(30614):    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:560)
03-08 13:48:01.593: E/AndroidRuntime(30614):    at dalvik.system.NativeStart.main(Native Method)
03-08 13:48:01.593: E/AndroidRuntime(30614): Caused by: java.lang.reflect.InvocationTargetException
03-08 13:48:01.593: E/AndroidRuntime(30614):    at java.lang.reflect.Constructor.constructNative(Native Method)
03-08 13:48:01.593: E/AndroidRuntime(30614):    at java.lang.reflect.Constructor.newInstance(Constructor.java:417)
03-08 13:48:01.593: E/AndroidRuntime(30614):    at android.view.LayoutInflater.createView(LayoutInflater.java:587)
03-08 13:48:01.593: E/AndroidRuntime(30614):    ... 20 more
03-08 13:48:01.593: E/AndroidRuntime(30614): Caused by: java.lang.NoClassDefFoundError: com.google.android.gms.R$styleable
03-08 13:48:01.593: E/AndroidRuntime(30614):    at com.google.android.gms.maps.GoogleMapOptions.createFromAttributes(Unknown Source)
03-08 13:48:01.593: E/AndroidRuntime(30614):    at com.google.android.gms.maps.MapView.<init>(Unknown Source)

layout xml: (the layout will change I just wanted to get the map working first)

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

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

</LinearLayout>

and my fragment

public class CurrentIncidentMapFrag extends Fragment {

@Override
public View onCreateView(LayoutInflater inflater,ViewGroup container,Bundle saved){
    View v = inflater.inflate(R.layout.current_incident_mapping_layout,container,false);

    return v;
}

}

I know there is a map fragment but I want to have more than just a map and I dont want it to take up the whole view in the fragment so a fragment with a view containing everything is my only option.

How can I get the map to show up?

tyczj
  • 71,600
  • 54
  • 194
  • 296

1 Answers1

0

I dont really get it, you are saying that you want to use Google Map API V2. but you are trying to use the MapView object that is a Google Map API V1 object. if you want to create a map with version to head here:

link

this is a post i wrote on creating Google Map API V2.

Emil Adz
  • 40,709
  • 36
  • 140
  • 187
  • 1
    No I am not trying to use the mapview object from v1 I want to use the MapView object from v2. I want to create a fragment with a map but I dont want to map to be the only thing in the view. I need to add some other views to the layout – tyczj Mar 08 '13 at 19:43
  • there is no MapView object in Google Maps API V2, you should use the MapFragment or the SupportMapFragment depending on what your target platform version. – Emil Adz Mar 08 '13 at 19:45
  • 1
    but if I use a map fragment then the only thing that will be in the view is the map right?? I dont want that I want to add some views below the map – tyczj Mar 08 '13 at 19:47
  • that's the beauty of fragment, they don't have to take up all the screen size... you can make a half screen map and bellow it add your desired buttons. – Emil Adz Mar 08 '13 at 19:48
  • for example here is an application with a map i did not a while ago using MapFragment: http://stackoverflow.com/questions/14469208/is-there-a-way-to-implement-rounded-corners-to-a-mapfragment – Emil Adz Mar 08 '13 at 19:49
  • right I understand you can change the dimensions of a fragment but I am talking about the view of the fragment. Going with your example you have a layout with 3 fragments (or frames to hold the fragments) i am guessing right? I only have 1 frame to put fragments in which is why I want the layout of the fragment like I do. There has to be some way I can change the layout of a fragment to add stuff like buttons and such – tyczj Mar 08 '13 at 19:54
  • So why wont you add 2 fragments, one that has a map and a fragment with all your buttons right after it? – Emil Adz Mar 08 '13 at 20:04
  • because the activity does more than just show a map, I have the activity doing dynamic fragments and adding another fragment to the layout would mess up the layout. What would I do to with the empty fragment when I am not showing the map? – tyczj Mar 08 '13 at 20:12
  • what do you mean by an "empty" fragment? the fragment with your map related buttons? remove this fragment as well when you remove your map fragment. and add other desired fragment after this action. – Emil Adz Mar 08 '13 at 20:17
  • @EmilAdz If MapView doesn't exist in the Google Maps API v2 for Android, then why is it in the docs? Furthermore, I can't find any evidence that it's not in the API. – Alex Fu Jun 28 '13 at 14:26
  • Hi EmilAdz You didnt got what **tyczj** wants. He wants **Map** as a **view** or **object** ie **(com.google.android.gms.maps.MapView)**. SO that he can add some other views **before** and **after** mapView. Hi @tyczj i also gone through this requirement Plz check this http://stackoverflow.com/questions/16182880/android-how-to-add-google-map-options-from-xml-layout – KK_07k11A0585 Jul 25 '13 at 07:26