2016-07-28 65 views
0

我的問題是我無法在android上使用API​​ 10上的map v2。這是錯誤:api上的GoogleMaps V2 10

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的服裝抽象活動;我進口

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> 

什麼我可以做任何建議嗎?

+0

試試這個; http://stackoverflow.com/questions/38637778/android-inflateexception-error-in-fragment-layout-with-supportmapfragment-recre/38639229#38639229 – Eenvincible

+0

@Eenvincible,我試過,但它沒有工作.. – hackingforgirls

回答

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> 
+0

我已編輯和發佈了我所有的.xml文件 – hackingforgirls

相關問題