2016-07-12 7 views
0

NavigationDrawerベースのアプリケーションがあります。読み込んだフラグメントの1つにGoogleMapフラグメントが含まれています。戻るボタンで入力するとフラグメントがクラッシュする

これはどんな問題なしの断片に

getSupportFragmentManager().beginTransaction().replace(R.id.container, 
    new MyMapFragment()).addToBackStack("mytag1").commit(); 

ページのロードをロードするために使用していると私はアプリケーションのクラッシュをメニューを使用して別のフラグメントに切り替えて戻るボタンを押したときにmap.Butを表示するものです。フラグメントには、マップをロードするための最小限のコードしか含まれていません。

フラグメントXML:

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

     try { 
      fm = ((SupportMapFragment) getChildFragmentManager() 
        .findFragmentById(R.id.map)); 

      if (fm != null) 
       map = fm.getMap(); 
      else 
       map = null; 
     } 
     catch(Exception e) 
     { Log.i("dbg",e.toString()); }       
} 

上記発火しません:アクティビティが

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    xmlns:tools="http://schemas.android.com/tools" 
    android:id="@+id/ll_report_in_out" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:background="@color/white" 
    android:orientation="vertical" 
    tools:context="my.package.name" > 

     <LinearLayout 
      android:id="@+id/llv_layer2" 
      android:layout_width="match_parent" 
      android:layout_height="match_parent" 
      android:layout_weight="1" 
      android:orientation="vertical" 
     > 
      <!-- some content --> 
     </LinearLayout> 

     <fragment 
      android:id="@+id/map" 
      android:layout_width="match_parent" 
      android:layout_height="match_parent" 
      android:layout_weight="1" 
      class="com.google.android.gms.maps.SupportMapFragment" 
      android:name="my.package.name.MyMapFragment" 
     /> 
</LinearLayout> 

。 Logcatは、マップのフラグメントが配置されている行125に例外を拡張します。私は本当に任意の助けをいただければ幸いです

...

私はそれが重要な場合には私の現在の試験条件や作業環境を追加してい

AndroidStudio 2.1 分SDK版10 ターゲットSDK版24 コンパイルSDKネクサス6の24

テストは、Android 6.0.1

+1

Fragmentに戻るときに 'onCreateView'メソッドが呼び出されますか? –

+0

@ρяσѕρєяKはい戻るボタンを押すと、onCreateViewが再び呼び出されます。 – Deepak

答えて

0

を実行しているVerは直接よりMapViewを使用してみてくださいxmlファイル内

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    xmlns:tools="http://schemas.android.com/tools" 
    xmlns:scrolling_image_view="http://schemas.android.com/apk/res-auto" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:orientation="vertical" 
    tools:context=".screens.DashBoardFragment"> 
    <!-- Component 1 to cover half screen height --> 
    <FrameLayout 
     android:layout_width="match_parent" 
     android:layout_height="0dp" 
     android:layout_weight="0.50" 
     android:layout_gravity="top" 
     > 

     <EditText android:id="@+id/url_live_target" 
       android:layout_width="match_parent" 
       android:layout_height="wrap_content" 
       android:textSize="@dimen/textSizeNormal" 
       android:inputType="textUri" 
       android:singleLine="true" 
       android:hint="Receive Live Update URL" /> 
    </FrameLayout> 

    <!-- Component 2 to cover half screen height --> 
    <FrameLayout 
     android:layout_width="match_parent" 
     android:layout_height="0dp" 
     android:layout_weight="0.50" 
     > 

     <com.google.android.gms.maps.MapView 
      xmlns:android="http://schemas.android.com/apk/res/android" 
      android:id="@+id/map_dashBoard" 
      android:layout_width="match_parent" 
      android:layout_height="match_parent" 
      android:layout_gravity="bottom" 
      /> 
      </FrameLayout> 
</LinearLayout> 

は、今すぐあなたのフラグメント

private MapView mMapView; 
    private GoogleMap mGoogleMap; 

    @Override 
    public View onCreateView(LayoutInflater inflater, ViewGroup container, 
          Bundle savedInstanceState) { 
     View view= inflater.inflate(R.layout.fragment_dash_board, container, false); 

     mMapView = (MapView) view.findViewById(R.id.map_dashBoard); 
     mMapView.onResume(); 

     try { 
      MapsInitializer.initialize(getActivity().getApplicationContext()); 
     } catch (Exception e) { 
      e.printStackTrace(); 
     } 
     mGoogleMap = mMapView.getMap(); 

    } 

にあなたはあなたの正確な要件に基づいてロジックを編集する必要があるかもしれません。 [断片の追加/置換など]

+0

レイアウトからわかるように、私はそれを行うことができません、私はマップの上にいくつかのコンテンツを表示する必要があります。 – Deepak

+0

マップビューを含むフラグメントをロードしても、次のエラーが発生してもコードセグメントがクラッシュするnullオブジェクト参照でインターフェイスメソッド 'void maps.af.y.o()'を呼び出そうとしています。 – Deepak

+0

@Deepak:私は精緻化できますか? "void maps.af.y.o()" – Stallion

0

このコードを試してください。これは

@Override 
public View onCreateView(LayoutInflater inflater, ViewGroup container,Bundle savedInstanceState) { 
if(view != null) 
{ 
    ViewGroup parent = (ViewGroup) container; 
    if(parent !=null) 
    { 
    parent.removeView(view); 
    } 
} 
try 
{ 
    view = inflater.inflate(R.layout.fragment_report_in_out, container, false); 
} 
catch(Exception e){} 
return view; 
} 

は、この情報がお役に立てば幸いです。この状態を確認してください)(onCreateViewで

View view = null; 

私の問題を解決しました!

関連する問題