我先说一下,我看到有几个人发布了完全相同的错误。 然而,我已经尝试了所有十种不同的解决方案,但仍然得到完全相同的堆栈跟踪和ANR错误。 我正在使用标准Tabs + Swipe模板,并且除了将第一个页面设置为返回我下面将显示的ListView片段之外,没有改变任何内容。
以下是我的片段代码。 CacheFrament仅是一个扩展android.support.v4.app.Fragment的超类。 在这种情况下,我尝试过仅返回listview以及其父级,但都无济于事。
任何帮助都将不胜感激。此错误基本上正在拖延一切。
以下是我的片段代码。 CacheFrament仅是一个扩展android.support.v4.app.Fragment的超类。 在这种情况下,我尝试过仅返回listview以及其父级,但都无济于事。
public class RoutesFragment extends CacheFragment {
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
View view = inflater.inflate(R.layout.list_view_layout, container);
listView.setAdapter(new ArrayAdapter<String>(getActivity(), android.R.layout.simple_list_item_1, new String[]{"No Routes Available"}));
return view;
}
}
这是我在片段中使用的布局,最初我将ListView作为父级,但也不起作用
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent">
<ListView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="@+id/main_list_view"/>
</LinearLayout>
最后,这是我一直收到的堆栈跟踪。请注意,这是我每次都遇到的完全相同的错误。
07-28 11:54:43.747 15074-15074/? E/AndroidRuntime: FATAL EXCEPTION: main
java.lang.IllegalStateException: The specified child already has a parent. You must call removeView() on the child's parent first.
at android.view.ViewGroup.addViewInner(ViewGroup.java:3387)
at android.view.ViewGroup.addView(ViewGroup.java:3258)
at android.view.ViewGroup.addView(ViewGroup.java:3203)
at android.view.ViewGroup.addView(ViewGroup.java:3179)
at android.support.v4.app.NoSaveStateFrameLayout.wrap(NoSaveStateFrameLayout.java:40)
at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:915)
at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:1088)
at android.support.v4.app.BackStackRecord.run(BackStackRecord.java:682)
at android.support.v4.app.FragmentManagerImpl.execPendingActions(FragmentManager.java:1444)
at android.support.v4.app.FragmentManagerImpl.executePendingTransactions(FragmentManager.java:461)
at android.support.v4.app.FragmentPagerAdapter.finishUpdate(FragmentPagerAdapter.java:141)
at android.support.v4.view.ViewPager.populate(ViewPager.java:1064)
at android.support.v4.view.ViewPager.populate(ViewPager.java:911)
at android.support.v4.view.ViewPager.onMeasure(ViewPager.java:1432)
at android.view.View.measure(View.java:15364)
at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:4824)
at android.widget.FrameLayout.onMeasure(FrameLayout.java:310)
at android.view.View.measure(View.java:15364)
at android.widget.LinearLayout.measureVertical(LinearLayout.java:833)
at android.widget.LinearLayout.onMeasure(LinearLayout.java:574)
at android.view.View.measure(View.java:15364)
at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:4824)
at android.widget.FrameLayout.onMeasure(FrameLayout.java:310)
at com.android.internal.policy.impl.PhoneWindow$DecorView.onMeasure(PhoneWindow.java:2359)
at android.view.View.measure(View.java:15364)
at android.view.ViewRootImpl.performMeasure(ViewRootImpl.java:1974)
at android.view.ViewRootImpl.measureHierarchy(ViewRootImpl.java:1217)
at android.view.ViewRootImpl.performTraversals(ViewRootImpl.java:1390)
at android.view.ViewRootImpl.doTraversal(ViewRootImpl.java:1110)
at android.view.ViewRootImpl$TraversalRunnable.run(ViewRootImpl.java:4472)
at android.view.Choreographer$CallbackRecord.run(Choreographer.java:725)
at android.view.Choreographer.doCallbacks(Choreographer.java:555)
at android.view.Choreographer.doFrame(Choreographer.java:525)
at android.view.Choreographer$FrameDisplayEventReceiver.run(Choreographer.java:711)
at android.os.Handler.handleCallback(Handler.java:615)
at android.os.Handler.dispatchMessage(Handler.java:92)
at android.os.Looper.loop(Looper.java:137)
at android.app.ActivityThread.main(ActivityThread.java:4918)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:511)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1004)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:771)
at dalvik.system.NativeStart.main(Native Method)
任何帮助都将不胜感激。此错误基本上正在拖延一切。