0

我在我的layout中加入fragment layout,在我的fragment layout是鏈接地址,當我觸摸鏈接時,我重定向到網絡瀏覽器,但當我回到應用程序讓我崩潰,並說不能inflate fragment不能在Android中擴充碎片?

我activity_map.xml:

<?xml version="1.0" encoding="utf-8"?> 
<android.support.v4.widget.DrawerLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:id="@+id/drawer_layout" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent"> 

    <LinearLayout 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" 
     android:orientation="vertical"> 

     <!-- The main content view --> 

     <FrameLayout 
      android:id="@+id/map_container" 
      android:layout_width="match_parent" 
      android:layout_height="match_parent"> 

     </FrameLayout> 
    </LinearLayout> 


    <FrameLayout 
     android:id="@+id/onebox_fragment" 
     android:layout_width="fill_parent" 
     android:layout_height="fill_parent"> 

    </FrameLayout> 

    <!-- The navigation drawer --> 
    <ListView 
     android:id="@+id/left_drawer" 
     style="@style/left_drawer_list" /> 
</android.support.v4.widget.DrawerLayout> 

和fragment_map.xml:

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    xmlns:tools="http://schemas.android.com/tools" 
    android:id="@+id/layout_root" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent"> 

    <FrameLayout 
     android:id="@+id/contentFrameLayout" 
     android:layout_width="fill_parent" 
     android:layout_height="fill_parent" 
     android:background="#80000000"> 

     <RelativeLayout 
      android:id="@+id/map_layout_root" 
      android:layout_width="match_parent" 
      android:layout_height="match_parent"> 

      <FrameLayout 
       android:id="@+id/frameLayout" 
       android:layout_width="fill_parent" 
       android:layout_height="fill_parent" 
       android:background="#80000000"> 

       <com.skobbler.ngx.map.SKMapViewHolder 
        android:id="@+id/view_group_map" 
        android:layout_width="fill_parent" 
        android:layout_height="fill_parent" /> 

       <RelativeLayout 
        android:id="@+id/chess_board_background" 
        android:layout_width="fill_parent" 
        android:layout_height="fill_parent" 
        android:background="@drawable/map_background"> 


       </RelativeLayout> 
      </FrameLayout> 

      <include 
       android:id="@+id/real_reach_time_layout" 
       layout="@layout/element_real_reach_time" 
       android:layout_width="fill_parent" 
       android:layout_height="fill_parent" 
       android:layout_alignParentTop="true" 
       android:visibility="gone" /> 

      <include 
       android:id="@+id/alt_routes" 
       layout="@layout/layout_alternative_routes" 
       android:layout_width="match_parent" 
       android:layout_height="wrap_content" 
       android:layout_alignParentTop="true" 
       android:visibility="gone" /> 

      <include 
       android:id="@+id/map_styles" 
       layout="@layout/layout_map_styles" 
       android:layout_width="match_parent" 
       android:layout_height="wrap_content" 
       android:layout_alignParentBottom="true" 
       android:visibility="gone" /> 

      <include 
       android:id="@+id/navigation_ui_layout" 
       layout="@layout/layout_navigation_ui" 
       android:layout_width="wrap_content" 
       android:layout_height="wrap_content" 
       android:visibility="gone" /> 

      <Button 
       android:id="@+id/bottom_button" 
       style="@style/button_style" 
       android:text="@string/navigate" 
       android:visibility="gone" /> 

      <Button 
       android:id="@+id/position_me_button" 
       style="@style/button_style" 
       android:layout_alignParentLeft="true" 
       android:layout_marginLeft="10dp" 
       android:text="@string/label_position_me" /> 

      <Button 
       android:id="@+id/heading_button" 
       style="@style/button_style" 
       android:layout_alignParentRight="true" 
       android:layout_marginRight="10dp" 
       android:text="@string/label_heading" /> 

      <ImageView 
       android:id="@+id/customView" 
       android:layout_width="wrap_content" 
       android:layout_height="wrap_content" 
       android:src="@drawable/icon_searchcenter_favorite" 
       android:visibility="invisible" /> 

     </RelativeLayout> 
    </FrameLayout> 

</RelativeLayout> 

,當我得到記錄從我的應用程序:

當我重定向到網絡瀏覽器的活動中去onPause()但是當我在software back上重新啓動活動並且不從onResum()開始活動。

我MapFragment.java:

public class MapFragment extends Fragment implements SKMapsInitializationListener { 
    @Override 
    public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { 
     SKMaps.getInstance().initializeSKMaps(this.getActivity().getApplication(), this); 
     View view = inflater.inflate(R.layout.fragment_map, null); 
     ((MapActivity) getActivity()).initialize(view); 
     return view; 
    } 

    @Override 
    public void onLibraryInitialized(boolean isSuccessful) { 
     if (isSuccessful) { 
      Log.i("LOG", "Success"); 
     } else { 
      Log.i("LOG", "UnSuccess"); 
     } 
    } 
} 

我MapActivity.java是在這裏:All of code

我崩潰的是:

FATAL EXCEPTION: main 
     java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.asheq.skobb_me_2/com.example.asheq.skobb_me_2.activity.MapActivity}: android.view.InflateException: Binary XML file line #24: Error inflating class com.skobbler.ngx.map.SKMapViewHolder 
      at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2214) 
      at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2264) 
      at android.app.ActivityThread.access$600(ActivityThread.java:144) 
      at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1259) 
      at android.os.Handler.dispatchMessage(Handler.java:99) 
      at android.os.Looper.loop(Looper.java:137) 
      at android.app.ActivityThread.main(ActivityThread.java:5148) 
      at java.lang.reflect.Method.invokeNative(Native Method) 
      at java.lang.reflect.Method.invoke(Method.java:525) 
      at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:737) 
      at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:553) 
      at dalvik.system.NativeStart.main(Native Method) 
     Caused by: android.view.InflateException: Binary XML file line #24: Error inflating class com.skobbler.ngx.map.SKMapViewHolder 
      at android.view.LayoutInflater.createView(LayoutInflater.java:620) 
      at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:696) 
      at android.view.LayoutInflater.rInflate(LayoutInflater.java:755) 
      at android.view.LayoutInflater.rInflate(LayoutInflater.java:758) 
      at android.view.LayoutInflater.rInflate(LayoutInflater.java:758) 
      at android.view.LayoutInflater.rInflate(LayoutInflater.java:758) 
      at android.view.LayoutInflater.inflate(LayoutInflater.java:492) 
      at android.view.LayoutInflater.inflate(LayoutInflater.java:397) 
      at android.view.LayoutInflater.inflate(LayoutInflater.java:353) 
      at com.example.asheq.skobb_me_2.fragments.MapFragment.onCreateView(MapFragment.java:26) 
      at android.app.Fragment.performCreateView(Fragment.java:1699) 
      at android.app.FragmentManagerImpl.moveToState(FragmentManager.java:885) 
      at android.app.FragmentManagerImpl.moveToState(FragmentManager.java:1057) 
      at android.app.FragmentManagerImpl.moveToState(FragmentManager.java:1039) 
      at android.app.FragmentManagerImpl.dispatchActivityCreated(FragmentManager.java:1840) 
      at android.app.Activity.performCreate(Activity.java:5239) 
      at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1087) 
      at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2178) 
      at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2264)  
      at android.app.ActivityThread.access$600(ActivityThread.java:144)  
      at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1259)  
      at android.os.Handler.dispatchMessage(Handler.java:99)  
      at android.os.Looper.loop(Looper.java:137)  
      at android.app.ActivityThread.main(ActivityThread.java:5148)  
      at java.lang.reflect.Method.invokeNative(Native Method)  
      at java.lang.reflect.Method.invoke(Method.java:525)  
      at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:737)  
      at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:553)  
      at dalvik.system.NativeStart.main(Native Method)  
     Caused by: java.lang.reflect.InvocationTargetException 
      at java.lang.reflect.Constructor.constructNative(Native Method) 
      at java.lang.reflect.Constructor.newInstance(Constructor.java:417) 
      at android.view.LayoutInflater.createView(LayoutInflater.java:594) 
      at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:696)  
      at android.view.LayoutInflater.rInflate(LayoutInflater.java:755)  
      at android.view.LayoutInflater.rInflate(LayoutInflater.java:758)  
      at android.view.LayoutInflater.rInflate(LayoutInflater.java:758)  
      at android.view.LayoutInflater.rInflate(LayoutInflater.java:758)  
      at android.view.LayoutInflater.inflate(LayoutInflater.java:492)  
      at android.view.LayoutInflater.inflate(LayoutInflater.java:397)  
      at android.view.LayoutInflater.inflate(LayoutInflater.java:353)  
      at com.example.asheq.skobb_me_2.fragments.MapFragment.onCreateView(MapFragment.java:26)  
      at android.app.Fragment.performCreateView(Fragment.java:1699)  
      at android.app.FragmentManagerImpl.moveToState(FragmentManager.java:885)  
      at android.app.FragmentManagerImpl.moveToState(FragmentManager.java:1057)  
      at android.app.FragmentManagerImpl.moveToState(FragmentManager.java:1039)  
      at android.app.FragmentManagerImpl.dispatchActivityCreated(FragmentManager.java:1840)  
      at android.app.Activity.performCreate(Activity.java:5239)  
      at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1087)  
      at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2178)  
      at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2264)  
      at android.app.ActivityThread.access$600(ActivityThread.java:144)  
      at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1259)  
      at android.os.Handler.dispatchMessage(Handler.java:99)  
      at android.os.Looper.loop(Looper.java:137)  
      at android.app.ActivityThread.main(ActivityThread.java:5148)  
      at java.lang.reflect.Method.invokeNative(Native Method)  
      at java.lang.reflect.Method.invoke(Method.java:525)  
      at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:737)  
      at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:553)  
      at dalvik.system.NativeStart.main(Native Method)  
     Caused by: java.lang.NullPointerException 
      at com.skobbler.ngx.map.SKMapViewHolder.a(SourceFile:254) 
      at com.skobbler.ngx.map.SKMapViewHolder.<init>(SourceFile:159) 
      at java.lang.reflect.Constructor.constructNative(Native Method)  
      at java.lang.reflect.Constructor.newInstance(Constructor.java:417)  
      at android.view.LayoutInflater.createView(LayoutInflater.java:594)  
      at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:696)  
      at android.view.LayoutInflater.rInflate(LayoutInflater.java:755)  
      at android.view.LayoutInflater.rInflate(LayoutInflater.java:758)  
      at android.view.LayoutInflater.rInflate(LayoutInflater.java:758)  
      at android.view.LayoutInflater.rInflate(LayoutInflater.java:758)  
      at android.view.LayoutInflater.inflate(LayoutInflater.java:492)  
      at android.view.LayoutInflater.inflate(LayoutInflater.java:397)  
      at android.view.LayoutInflater.inflate(LayoutInflater.java:353)  
      at com.example.asheq.skobb_me_2.fragments.MapFragment.onCreateView(MapFragment.java:26)  
      at android.app.Fragment.performCreateView(Fragment.java:1699)  
      at android.app.FragmentManagerImpl.moveToState(FragmentManager.java:885)  
      at android.app.FragmentManagerImpl.moveToState(FragmentManager.java:1057)  
      at android.app.FragmentManagerImpl.moveToState(FragmentManager.java:1039)  
      at android.app.FragmentManagerImpl.dispatchActivityCreated(FragmentManager.java:1840)  
      at android.app.Activity.performCreate(Activity.java:5239)  
      at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1087)  
      at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2178)  
      at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2264)  
      at android.app.ActivityThread.access$600(ActivityThread.java:144)  
      at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1259)  
      at android.os.Handler.dispatchMessage(Handler.java:99)  
      at android.os.Looper.loop(Looper.java:137)  
      at android.app.ActivityThread.main(ActivityThread.java:5148)  
      at java.lang.reflect.Method.invokeNative(Native Method)  
      at java.lang.reflect.Method.invoke(Method.java:525)  
      at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:737)  
      at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:553)  
      at dalvik.system.NativeStart.main(Native Method)  

回答

0
<!-- The main content view --> 
    <FrameLayout 
     android:id="@+id/map_container" 

你的片段去那裏用了FragmentManager該活動並添加/替換爲R.id.map_container。你不需要添加任何其他FrameLayout不要讓名字欺騙你。它可以存儲多於僅地圖

如果要將多個Frame加載到一個視圖中,它們必須位於LinearLayout內,因爲這是Activity內容,而DrawerLayout使用兩個子項。

0

真正的問題是在這裏

Caused by: java.lang.NullPointerException 
     at com.skobbler.ngx.map.SKMapViewHolder.a(SourceFile:254) 

修復的NullPointerException在SKMapViewHolder