0

タブホストとフラグメントアクティビティを使用して、3 つのタブを持つアプリを作成します。最初のタブにマップがあり、最初に起動すると正常に動作し、タブを切り替えてアプリに戻るとマップが表示され、アプリがクラッシュし、クラス例外を膨張させるエラーが発生します。

これが私のタブ変更リスナーのコードです

getActivity().getSupportFragmentManager().beginTransaction().replace(placeholder, new MapView(), "Maps").commit();

これが私のフラグメントクラスのコードです

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
        Bundle savedInstanceState) {

        view = inflater.inflate(R.layout.map_view, container, false);

    return view;
}

これが私のlogcatです

    06-28 14:53:38.575: E/AndroidRuntime(9442): FATAL EXCEPTION: main
    06-28 14:53:38.575: E/AndroidRuntime(9442): android.view.InflateException: Binary XML file line #76: Error inflating class fragment
    06-28 14:53:38.575: E/AndroidRuntime(9442):     at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:587)
    06-28 14:53:38.575: E/AndroidRuntime(9442):     at android.view.LayoutInflater.rInflate(LayoutInflater.java:623)
    06-28 14:53:38.575: E/AndroidRuntime(9442):     at android.view.LayoutInflater.rInflate(LayoutInflater.java:626)
    06-28 14:53:38.575: E/AndroidRuntime(9442):     at android.view.LayoutInflater.inflate(LayoutInflater.java:408)
    06-28 14:53:38.575: E/AndroidRuntime(9442):     at android.view.LayoutInflater.inflate(LayoutInflater.java:320)
    06-28 14:53:38.575: E/AndroidRuntime(9442):     at com.mymapapp.app.MapView.onCreateView(MapView.java:27)
    06-28 14:53:38.575: E/AndroidRuntime(9442):     at android.support.v4.app.Fragment.performCreateView(Fragment.java:1460)
    06-28 14:53:38.575: E/AndroidRuntime(9442):     at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:911)
    06-28 14:53:38.575: E/AndroidRuntime(9442):     at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:1088)
    06-28 14:53:38.575: E/AndroidRuntime(9442):     at android.support.v4.app.BackStackRecord.run(BackStackRecord.java:682)
    06-28 14:53:38.575: E/AndroidRuntime(9442):     at android.support.v4.app.FragmentManagerImpl.execPendingActions(FragmentManager.java:1444)
    06-28 14:53:38.575: E/AndroidRuntime(9442):     at android.support.v4.app.FragmentManagerImpl$1.run(FragmentManager.java:429)
    06-28 14:53:38.575: E/AndroidRuntime(9442):     at android.os.Handler.handleCallback(Handler.java:587)
    06-28 14:53:38.575: E/AndroidRuntime(9442):     at android.os.Handler.dispatchMessage(Handler.java:92)
    06-28 14:53:38.575: E/AndroidRuntime(9442):     at android.os.Looper.loop(Looper.java:123)
    06-28 14:53:38.575: E/AndroidRuntime(9442):     at android.app.ActivityThread.main(ActivityThread.java:3691)
    06-28 14:53:38.575: E/AndroidRuntime(9442):     at java.lang.reflect.Method.invokeNative(Native Method)
    06-28 14:53:38.575: E/AndroidRuntime(9442):     at java.lang.reflect.Method.invoke(Method.java:507)
    06-28 14:53:38.575: E/AndroidRuntime(9442):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:847)
    06-28 14:53:38.575: E/AndroidRuntime(9442):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:605)
    06-28 14:53:38.575: E/AndroidRuntime(9442):     at dalvik.system.NativeStart.main(Native Method)
    06-28 14:53:38.575: E/AndroidRuntime(9442): Caused by: java.lang.IllegalArgumentException: Binary XML file line #76: Duplicate id 0x7f050058, tag null, or parent id 0x0 with another fragment for com.mymapapp.custom.views.TransparentSupportMapFragment
    06-28 14:53:38.575: E/AndroidRuntime(9442):     at android.support.v4.app.FragmentActivity.onCreateView(FragmentActivity.java:285)
    06-28 14:53:38.575: E/AndroidRuntime(9442):     at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:563)
    06-28 14:53:38.575: E/AndroidRuntime(9442):     ... 20 more
4

1 に答える 1

1

これは Vidar によってここで回答されました: com.google.android.gms.maps.MapFragment の別のフラグメントを持つ重複 ID、タグ null、または親 ID

彼の解決策は次のとおりです。

if (view != null) {
    ViewGroup parent = (ViewGroup) view.getParent();
    if (parent != null)
        parent.removeView(view);
}
try {
    view = inflater.inflate(R.layout.map, container, false);
} catch (InflateException e) {
    /* map is already there, just return view as it is */
}
return view;
于 2013-06-28T16:41:22.117 に答える