关于api 10的GoogleMaps V2

时间:2016-07-28 15:17:41

标签: android google-maps-api-2

我的问题是我无法在Android上的API 10上使用map v2。这是错误:

Failed to inflate
                                                                    android.view.InflateException: Binary XML file line #106: Error inflating class fragment
                                                                        at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:581)
                                                                        at android.view.LayoutInflater.rInflate(LayoutInflater.java:623)
                                                                        at android.view.LayoutInflater.inflate(LayoutInflater.java:408)
                                                                        at android.view.LayoutInflater.inflate(LayoutInflater.java:320)
                                                                        at android.view.LayoutInflater.inflate(LayoutInflater.java:276)
                                                                        at com.ter.androidapp.activities.RootActivity.onCreate(RootActivity.java:385)
                                                                        at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047)
                                                                        at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1722)
                                                                        at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1784)
                                                                        at android.app.ActivityThread.access$1500(ActivityThread.java:123)
                                                                        at android.app.ActivityThread$H.handleMessage(ActivityThread.java:939)
                                                                        at android.os.Handler.dispatchMessage(Handler.java:99)
                                                                        at android.os.Looper.loop(Looper.java:130)
                                                                        at android.app.ActivityThread.main(ActivityThread.java:3835)
                                                                        at java.lang.reflect.Method.invokeNative(Native Method)
                                                                        at java.lang.reflect.Method.invoke(Method.java:507)
                                                                        at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:864)
                                                                        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:622)
                                                                        at dalvik.system.NativeStart.main(Native Method)
                                                                     Caused by: java.lang.ClassNotFoundException: android.view.fragment in loader dalvik.system.PathClassLoader[/data/app/com.ter.androidapp-1.apk]
                                                                        at dalvik.system.PathClassLoader.findClass(PathClassLoader.java:240)
                                                                        at java.lang.ClassLoader.loadClass(ClassLoader.java:551)
                                                                        at java.lang.ClassLoader.loadClass(ClassLoader.java:511)
                                                                        at android.view.LayoutInflater.createView(LayoutInflater.java:471)
                                                                        at android.view.LayoutInflater.onCreateView(LayoutInflater.java:549)
                                                                        at com.android.internal.policy.impl.PhoneLayoutInflater.onCreateView(PhoneLayoutInflater.java:66)
                                                                        at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:568)
                                                                        at android.view.LayoutInflater.rInflate(LayoutInflater.java:623) 
                                                                        at android.view.LayoutInflater.inflate(LayoutInflater.java:408) 
                                                                        at android.view.LayoutInflater.inflate(LayoutInflater.java:320) 
                                                                        at android.view.LayoutInflater.inflate(LayoutInflater.java:276) 
                                                                        at com.ter.androidapp.activities.RootActivity.onCreate(RootActivity.java:385) 
                                                                        at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047) 
                                                                        at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1722) 
                                                                        at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1784) 
                                                                        at android.app.ActivityThread.access$1500(ActivityThread.java:123) 
                                                                        at android.app.ActivityThread$H.handleMessage(ActivityThread.java:939) 
                                                                        at android.os.Handler.dispatchMessage(Handler.java:99) 
                                                                        at android.os.Looper.loop(Looper.java:130) 
                                                                        at android.app.ActivityThread.main(ActivityThread.java:3835) 
                                                                        at java.lang.reflect.Method.invokeNative(Native Method) 
                                                                        at java.lang.reflect.Method.invoke(Method.java:507) 
                                                                        at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:864) 
                                                                        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:622) 
                                                                        at dalvik.system.NativeStart.main(Native Method) 

我的活动扩展了一个扩展FragmentActivit的costum抽象活动;我导入

import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentActivity;

当它试图用地图片段膨胀布局时崩溃:

        if (mMapViewContainer == null) {
            mMapViewContainer = getLayoutInflater().inflate(R.layout.fragment_geoloc_map, null); <-here it crash!
            mapFragment = (SupportMapFragment) getSupportFragmentManager().findFragmentById(R.id.mapview_geolo);
            mapFragment.getMapAsync(this);
        }

fragment_geoloc_map中的片段是:

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:id="@+id/topLayout"
    android:background="@color/transparent" >

    <TextView
        android:id="@+id/textView_trainNum"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:layout_alignParentTop="true"
        android:gravity="center"
        android:padding="5dip"
        android:textSize="@dimen/xxLargeText"
        android:visibility="gone" />

    <RelativeLayout
        android:id="@+id/geolocInfoContainer"
        android:layout_width="fill_parent"
        android:paddingBottom="10dip"
        android:layout_height="wrap_content" >

        <TextView
            android:id="@+id/textView_title"
            android:layout_width="fill_parent"
            android:layout_height="60dip"
            android:layout_marginBottom="10dp"
            android:background="@drawable/btn_rechercher_red"
            android:gravity="center"
            android:paddingBottom="14dp"
            android:paddingTop="14dp"
            android:text="@string/selectStation"
            android:textColor="@color/white"
            android:textSize="@dimen/xxxLargeText"
            android:textStyle="bold" />

        <TextView
            android:id="@+id/textView_choose_radius"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_alignBottom="@+id/imageView_refresh_map"
            android:layout_alignTop="@+id/imageView_refresh_map"
            android:layout_marginRight="10dp"
            android:layout_toLeftOf="@+id/textView_radius"
            android:gravity="center_vertical"
            android:text="@string/radius"
            android:textColor="@color/darkGrey"
            android:textSize="@dimen/largeText" />

        <TextView
            android:id="@+id/textView_radius"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_alignBottom="@+id/imageView_refresh_map"
            android:layout_alignTop="@+id/imageView_refresh_map"
            android:layout_marginRight="5dp"
            android:layout_toLeftOf="@+id/imageView_refresh_map"
            android:background="@color/radiusGrey"
            android:drawableBottom="@drawable/ico_triangle_gris"
            android:gravity="center_vertical"
            android:paddingBottom="5dip"
            android:paddingLeft="15dip"
            android:paddingRight="15dip"
            android:text="@string/initial_radius"
            android:textColor="@color/radiusTextViewColor"
            android:textStyle="bold" />

        <ImageView
            android:id="@+id/imageView_refresh_map"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_below="@+id/textView_title"
            android:layout_marginRight="5dp"
            android:layout_toLeftOf="@+id/imageView_backToList"
            android:background="@color/red"
            android:padding="8dip"
            android:src="@drawable/ico_refresh" />

        <ImageView
            android:id="@+id/imageView_backToList"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_alignParentRight="true"
            android:layout_below="@+id/textView_title"
            android:layout_marginRight="10dip"
            android:background="@color/red"
            android:paddingBottom="8dip"
            android:paddingLeft="10dip"
            android:paddingRight="9dip"
            android:paddingTop="8dip"
            android:src="@drawable/ico_list_carte_red" />

    </RelativeLayout>



  <fragment
        class="com.google.android.gms.maps.SupportMapFragment"
        android:id="@+id/mapview_geolo"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:layout_below="@+id/geolocInfoContainer" />

</RelativeLayout>

关于我能做什么的任何建议?

1 个答案:

答案 0 :(得分:0)

您的fragment_geoloc_map作为xml文件看起来不正确。尝试这样的事情。

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

    <fragment
        class="com.google.android.gms.maps.SupportMapFragment"
        android:id="@+id/mapview_geolo"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:layout_below="@+id/geolocInfoContainer" />

</RelativeLayout>