重复id与另一个片段错误

时间:2014-06-03 13:32:01

标签: android android-fragments android-xml

我最近改变了一些导致一些问题的事情,我有一段时间试图弄清楚我哪里出错了。从Logcat看来我有一个重复的ID,但我不确定解决它的最佳方法。我试过更改XML文件中的ID和类似乎都不起作用。这是我得到的Logcat。

06-03 08:55:20.575    3530-3530/com.rcd.mypr E/AndroidRuntime﹕ FATAL EXCEPTION: main
    Process: com.rcd.mypr, PID: 3530
    java.lang.RuntimeException: Unable to start activity ComponentInfo{com.rcd.mypr/com.rcd.mypr.Workouts.WorkoutsArticleActivity}: android.view.InflateException: Binary XML file line #22: Error inflating class fragment
            at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2209)
            at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2269)
            at android.app.ActivityThread.access$800(ActivityThread.java:139)
            at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1210)
            at android.os.Handler.dispatchMessage(Handler.java:102)
            at android.os.Looper.loop(Looper.java:136)
            at android.app.ActivityThread.main(ActivityThread.java:5102)
            at java.lang.reflect.Method.invokeNative(Native Method)
            at java.lang.reflect.Method.invoke(Method.java:515)
            at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:779)
            at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:595)
            at dalvik.system.NativeStart.main(Native Method)
     Caused by: android.view.InflateException: Binary XML file line #22: Error inflating class fragment
            at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:713)
            at android.view.LayoutInflater.rInflate(LayoutInflater.java:755)
            at android.view.LayoutInflater.inflate(LayoutInflater.java:492)
            at android.view.LayoutInflater.inflate(LayoutInflater.java:397)
            at com.rcd.mypr.Workouts.WorkoutsArticleFragment.onCreateView(WorkoutsArticleFragment.java:42)
            at android.app.Fragment.performCreateView(Fragment.java:1700)
            at android.app.FragmentManagerImpl.moveToState(FragmentManager.java:866)
            at android.app.FragmentManagerImpl.moveToState(FragmentManager.java:1040)
            at android.app.FragmentManagerImpl.addFragment(FragmentManager.java:1142)
            at android.app.Activity.onCreateView(Activity.java:4803)
            at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:689)
            at android.view.LayoutInflater.rInflate(LayoutInflater.java:755)
            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.android.internal.policy.impl.PhoneWindow.setContentView(PhoneWindow.java:290)
            at android.app.Activity.setContentView(Activity.java:1937)
            at android.support.v7.app.ActionBarActivity.superSetContentView(ActionBarActivity.java:216)
            at android.support.v7.app.ActionBarActivityDelegateICS.setContentView(ActionBarActivityDelegateICS.java:110)
            at android.support.v7.app.ActionBarActivity.setContentView(ActionBarActivity.java:76)
            at com.rcd.mypr.Workouts.WorkoutsArticleActivity.onCreate(WorkoutsArticleActivity.java:70)
            at android.app.Activity.performCreate(Activity.java:5248)
            at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1110)
            at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2173)
            at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2269)
            at android.app.ActivityThread.access$800(ActivityThread.java:139)
            at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1210)
            at android.os.Handler.dispatchMessage(Handler.java:102)
            at android.os.Looper.loop(Looper.java:136)
            at android.app.ActivityThread.main(ActivityThread.java:5102)
            at java.lang.reflect.Method.invokeNative(Native Method)
            at java.lang.reflect.Method.invoke(Method.java:515)
            at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:779)
            at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:595)
            at dalvik.system.NativeStart.main(Native Method)
     Caused by: java.lang.IllegalArgumentException: Binary XML file line #22: Duplicate id 0x7f07004c, tag null, or parent id 0xffffffff with another fragment for com.rcd.mypr.Workouts.WorkoutsArticleFragment
            at android.app.Activity.onCreateView(Activity.java:4808)
            at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:689)
            at android.view.LayoutInflater.rInflate(LayoutInflater.java:755)
            at android.view.LayoutInflater.inflate(LayoutInflater.java:492)
            at android.view.LayoutInflater.inflate(LayoutInflater.java:397)
            at com.rcd.mypr.Workouts.WorkoutsArticleFragment.onCreateView(WorkoutsArticleFragment.java:42)
            at android.app.Fragment.performCreateView(Fragment.java:1700)
            at android.app.FragmentManagerImpl.moveToState(FragmentManager.java:866)
            at android.app.FragmentManagerImpl.moveToState(FragmentManager.java:1040)
            at android.app.FragmentManagerImpl.addFragment(FragmentManager.java:1142)
            at android.app.Activity.onCreateView(Activity.java:4803)
            at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:689)
            at android.view.LayoutInflater.rInflate(LayoutInflater.java:755)
            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.android.internal.policy.impl.PhoneWindow.setContentView(PhoneWindow.java:290)
            at android.app.Activity.setContentView(Activity.java:1937)
            at android.support.v7.app.ActionBarActivity.superSetContentView(ActionBarActivity.java:216)
            at android.support.v7.app.ActionBarActivityDelegateICS.setContentView(ActionBarActivityDelegateICS.java:110)
            at android.support.v7.app.ActionBarActivity.setContentView(ActionBarActivity.java:76)
            at com.rcd.mypr.Workouts.WorkoutsArticleActivity.onCreate(WorkoutsArticleActivity.java:70)
            at android.app.Activity.performCreate(Activity.java:5248)
            at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1110)
            at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2173)
            at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2269)
            at android.app.ActivityThread.access$800(ActivityThread.java:139)
            at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1210)
            at android.os.Handler.dispatchMessage(Handler.java:102)
            at android.os.Looper.loop(Looper.java:136)
            at android.app.ActivityThread.main(ActivityThread.java:5102)
            at java.lang.reflect.Method.invokeNative(Native Method)
            at java.lang.reflect.Method.invoke(Method.java:515)
            at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:779)
            at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:595)
            at dalvik.system.NativeStart.main(Native Method)

这里是WorkoutsArticleFragment:42

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

WorkoutsArticleActivity:70-73

setContentView(R.layout.activity_detail);
WorkoutsArticleFragment workoutsArticleFragment = (WorkoutsArticleFragment) getFragmentManager()
.findFragmentById(R.id.detailFragment);
workoutsArticleFragment.updateArticleView(workoutData);

ActivityDetail.xml

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical">

    <fragment
        android:id="@+id/detailFragment"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        class="com.rcd.mypr.Workouts.WorkoutsArticleFragment" />

</LinearLayout> 

fragment_workouts_article_view.xml

<?xml version="1.0" encoding="utf-8"?><!--
Copyright (C) 2012 The Android Open Source Project

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

     http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
-->
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:orientation="horizontal"
    android:background="@color/darkGray">

    <fragment
        android:id="@+id/detailFragment"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        class="com.rcd.mypr.Workouts.WorkoutsArticleFragment" >
    <ScrollView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:id="@+id/scrollView">

        <TableLayout
            android:layout_width="fill_parent"
            android:layout_height="fill_parent">

            <TableRow
                android:layout_width="fill_parent"
                android:layout_height="fill_parent">

                <TextView xmlns:android="http://schemas.android.com/apk/res/android"
                    android:id="@+id/workoutName"
                    android:layout_width="match_parent"
                    android:layout_height="match_parent"
                    android:padding="5dp"
                    android:textSize="30sp"
                    android:text="Workout Name"
                    android:textIsSelectable="true"
                    android:textColor="@color/white"
                    android:fontFamily="sans-serif-light" />


            </TableRow>

            <LinearLayout
                android:layout_width="match_parent"
                android:layout_height="2dip"
                android:orientation="vertical"
                android:layout_marginLeft="5dp"
                android:layout_marginRight="5dp"
                android:background="@color/white"></LinearLayout>

            <TableRow
                android:layout_width="fill_parent"
                android:layout_height="fill_parent">

                <ImageView
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:id="@+id/imageView"
                    android:gravity="center" />
            </TableRow>

            <TableRow
                android:layout_width="fill_parent"
                android:layout_height="fill_parent">

                <TextView
                    android:layout_width="0dp"
                    android:layout_height="wrap_content"
                    android:textAppearance="?android:attr/textAppearanceMedium"
                    android:text="Name: "
                    android:id="@+id/nameTextView"
                    android:paddingLeft="5dp"
                    android:textColor="@color/white"
                    android:layout_weight="1"
                    android:fontFamily="sans-serif-light" />
            </TableRow>

            <TableRow
                android:layout_width="fill_parent"
                android:layout_height="fill_parent">

                <TextView
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:textAppearance="?android:attr/textAppearanceMedium"
                    android:text="Hero Description"
                    android:id="@+id/heroDescription"
                    android:padding="5dp"
                    android:textColor="@color/white"
                    android:fontFamily="sans-serif-light" />
            </TableRow>


            <TextView
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="· · ·"
                android:textSize="50dp"
                android:gravity="center"
                android:id="@+id/divider"
                android:textColor="@color/white"
                android:fontFamily="sans-serif-light" />

            <TableRow
                android:layout_width="fill_parent"
                android:layout_height="fill_parent">

                <LinearLayout
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:orientation="vertical"
                    android:background="@drawable/dashed_line"
                    android:layout_marginLeft="5dp"
                    android:layout_marginRight="5dp">

                    <TextView
                        android:layout_width="wrap_content"
                        android:layout_height="wrap_content"
                        android:textAppearance="?android:attr/textAppearanceMedium"
                        android:text="Workout Measurement"
                        android:id="@+id/workoutMeasurement"
                        android:padding="5dp"
                        android:textColor="@color/white"
                        android:fontFamily="sans-serif-light" />

                    <TextView
                        android:layout_width="wrap_content"
                        android:layout_height="wrap_content"
                        android:textAppearance="?android:attr/textAppearanceMedium"
                        android:text="Workout Info"
                        android:id="@+id/workoutInfo"
                        android:padding="5dp"
                        android:textColor="@color/white"
                        android:fontFamily="sans-serif-light" />

                </LinearLayout>
            </TableRow>

            <TableRow
                android:layout_width="fill_parent"
                android:layout_height="fill_parent">

                <TextView
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:textAppearance="?android:attr/textAppearanceMedium"
                    android:text="Date Added: "
                    android:id="@+id/dateAdded"
                    android:padding="5dp"
                    android:textColor="@color/white"
                    android:fontFamily="sans-serif-light" />
            </TableRow>
        </TableLayout>

    </ScrollView>
    </fragment>

</LinearLayout>

有人可以提出一个关于如何解决这个问题的建议吗?再次,感觉我已经尝试交换片段的ID,以及类,但我要么得到一个NPE或这个错误。

1 个答案:

答案 0 :(得分:0)

我从xml文件中删除了以下内容,它再次正常工作。

<fragment
        android:id="@+id/detailFragment"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        class="com.rcd.mypr.Workouts.WorkoutsArticleFragment" >