我已经在其他类似的问题上搜索过这个,但我无法解决它。我的问题是我无法从另一个片段中打开一个片段,我正在这样做:
FragmentLugaresLista frag = new FragmentLugaresLista();
Bundle args = new Bundle();
args.putString("gastronomyElementType", "Restaurants");
frag.setArguments(args);
ActivityContenedor asd = new ActivityContenedor();
asd.openFragment(frag);
将方法openFragment变成ActivityContenedor:
public void openFragment(Fragment fragmentToOpen) {
FragmentManager manager = getFragmentManager();
manager.beginTransaction()
.replace(R.id.content_frame, fragmentToOpen).commit();
mDrawerLayout.closeDrawer(mDrawerList);
}
我有这个错误:
11-04 16:23:38.731: E/AndroidRuntime(20705): FATAL EXCEPTION: main
11-04 16:23:38.731: E/AndroidRuntime(20705): java.lang.IllegalStateException: Activity has been destroyed
11-04 16:23:38.731: E/AndroidRuntime(20705): at android.app.FragmentManagerImpl.enqueueAction(FragmentManager.java:1299)
11-04 16:23:38.731: E/AndroidRuntime(20705): at android.app.BackStackRecord.commitInternal(BackStackRecord.java:541)
11-04 16:23:38.731: E/AndroidRuntime(20705): at android.app.BackStackRecord.commit(BackStackRecord.java:525)
11-04 16:23:38.731: E/AndroidRuntime(20705): at com.example.despegarteproject.ActivityContenedor.openFragment(ActivityContenedor.java:113)
11-04 16:23:38.731: E/AndroidRuntime(20705): at com.example.despegarteproject.FragmentLugares$GridViewListener.onItemClick(FragmentLugares.java:242)
11-04 16:23:38.731: E/AndroidRuntime(20705): at android.widget.AdapterView.performItemClick(AdapterView.java:292)
11-04 16:23:38.731: E/AndroidRuntime(20705): at android.widget.AbsListView.performItemClick(AbsListView.java:1068)
11-04 16:23:38.731: E/AndroidRuntime(20705): at android.widget.AbsListView$PerformClick.run(AbsListView.java:2525)
11-04 16:23:38.731: E/AndroidRuntime(20705): at android.widget.AbsListView$1.run(AbsListView.java:3186)
11-04 16:23:38.731: E/AndroidRuntime(20705): at android.os.Handler.handleCallback(Handler.java:605)
11-04 16:23:38.731: E/AndroidRuntime(20705): at android.os.Handler.dispatchMessage(Handler.java:92)
11-04 16:23:38.731: E/AndroidRuntime(20705): at android.os.Looper.loop(Looper.java:137)
11-04 16:23:38.731: E/AndroidRuntime(20705): at android.app.ActivityThread.main(ActivityThread.java:4448)
11-04 16:23:38.731: E/AndroidRuntime(20705): at java.lang.reflect.Method.invokeNative(Native Method)
11-04 16:23:38.731: E/AndroidRuntime(20705): at java.lang.reflect.Method.invoke(Method.java:511)
11-04 16:23:38.731: E/AndroidRuntime(20705): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:823)
11-04 16:23:38.731: E/AndroidRuntime(20705): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:590)
11-04 16:23:38.731: E/AndroidRuntime(20705): at dalvik.system.NativeStart.main(Native Method)
你可以帮帮我吗?我将不胜感激。