IllegalArgumentException:找不到id的视图 - 在应用程序重启时

时间:2014-01-17 10:01:19

标签: android android-fragments

我的应用程序是使用片段和v4支持片段管理器构建的。该应用程序从启动运行良好,事实上我自己无法重新创建这个错误,所以原则上我的xml的结构很好。但是我的崩溃报告表明很多用户在返回应用程序时遇到崩溃,暂停后恢复它。我明白了:

IllegalArgumentException: No view found for id 0x7f06002d

请参阅下面的XML。报告为未找到的ID可能不同,它可以是任何一个嵌套的RelativeLayouts。为什么这些观点会随机消失/找不到?

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

    <RelativeLayout
    android:id="@+id/menuLayout"
    android:layout_width="50dp"
    android:layout_height="match_parent"
    android:layout_above="@+id/bottomFragmentLayout"
    android:layout_alignParentLeft="true"
    android:visibility="visible" >

    </RelativeLayout>

    <RelativeLayout
    android:id="@+id/whenLayout"
    android:layout_width="wrap_content"
    android:layout_height="match_parent"
    android:layout_above="@+id/bottomFragmentLayout"
    android:layout_toRightOf="@+id/menuLayout"
    android:visibility="invisible" >

    </RelativeLayout>

    <RelativeLayout
    android:id="@+id/howLayout"
    android:layout_width="wrap_content"
    android:layout_height="match_parent"
    android:layout_above="@+id/bottomFragmentLayout"
    android:layout_toRightOf="@+id/menuLayout"
    android:visibility="invisible" >

    </RelativeLayout>

    <RelativeLayout
    android:id="@+id/whereLayout"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:layout_above="@+id/bottomFragmentLayout"
    android:layout_toRightOf="@+id/menuLayout"
    android:visibility="invisible" >

    </RelativeLayout>

    <!-- The bottom bar -->
    <RelativeLayout
    android:id="@+id/bottomFragmentLayout"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_alignParentBottom="true"
    android:background="#999999" >
    </RelativeLayout>

</RelativeLayout>

编辑:完整堆栈跟踪:

java.lang.RuntimeException: Unable to start activity ComponentInfo{com.myapp.android/com.myapp.android.activity.MainFragmentActivity}: java.lang.IllegalArgumentException: No view found for id 0x7f060030 (com.myapp.android:id/howLayout) for fragment WhatFragment{4220b058 #4 id=0x7f060030 WhatFragment}
   at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2180)
   at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2230)
   at android.app.ActivityThread.handleRelaunchActivity(ActivityThread.java:3692)
   at android.app.ActivityThread.access$700(ActivityThread.java:141)
   at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1240)
   at android.os.Handler.dispatchMessage(Handler.java:99)
   at android.os.Looper.loop(Looper.java:137)
   at android.app.ActivityThread.main(ActivityThread.java:5039)
   at java.lang.reflect.Method.invokeNative(Method.java)
   at java.lang.reflect.Method.invoke(Method.java:511)
   at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:793)
   at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:560)
   at dalvik.system.NativeStart.main(NativeStart.java)
Caused by: java.lang.IllegalArgumentException: No view found for id 0x7f060030 (com.myapp.android:id/howLayout) for fragment WhatFragment{4220b058 #4 id=0x7f060030 WhatFragment}
   at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:919)
   at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:1104)
   at android.support.v4.app.BackStackRecord.run(BackStackRecord.java:682)
   at android.support.v4.app.FragmentManagerImpl.execPendingActions(FragmentManager.java:1467)
   at android.support.v4.app.FragmentActivity.onStart(FragmentActivity.java:570)
   at com.myapp.android.activity.MainFragmentActivity.onStart(MainFragmentActivity.java:449)
   at android.app.Instrumentation.callActivityOnStart(Instrumentation.java:1164)
   at android.app.Activity.performStart(Activity.java:5114)
   at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2153)
   at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2230)
   at android.app.ActivityThread.handleRelaunchActivity(ActivityThread.java:3692)
   at android.app.ActivityThread.access$700(ActivityThread.java:141)
   at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1240)
   at android.os.Handler.dispatchMessage(Handler.java:99)
   at android.os.Looper.loop(Looper.java:137)
   at android.app.ActivityThread.main(ActivityThread.java:5039)
   at java.lang.reflect.Method.invokeNative(Method.java)
   at java.lang.reflect.Method.invoke(Method.java:511)
   at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:793)
   at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:560)
   at dalvik.system.NativeStart.main(NativeStart.java)

1 个答案:

答案 0 :(得分:0)

// try this way
1. when you gave other layout reference like android:layout_above="@+id/bottomFragmentLayout" so here "+" sign removed from reference "+" is for new id declaration so we not declare new id but just gave already define id reference.
2. in your xml define bottom layout at last and try using this layout id before bottom layout declaration that y it's not finding such kind of layout so you have decalre first layout then gave reference as another layouyt which i correct in my ans.     

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

    <RelativeLayout
        android:id="@+id/bottomFragmentLayout"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentBottom="true"
        android:background="#999999" >
    </RelativeLayout>

    <RelativeLayout
        android:id="@+id/menuLayout"
        android:layout_width="50dp"
        android:layout_height="match_parent"
        android:layout_above="@id/bottomFragmentLayout"
        android:layout_alignParentLeft="true"
        android:visibility="visible" >

    </RelativeLayout>

    <RelativeLayout
        android:id="@+id/whenLayout"
        android:layout_width="wrap_content"
        android:layout_height="match_parent"
        android:layout_above="@id/bottomFragmentLayout"
        android:layout_toRightOf="@id/menuLayout"
        android:visibility="invisible" >

    </RelativeLayout>

    <RelativeLayout
        android:id="@+id/howLayout"
        android:layout_width="wrap_content"
        android:layout_height="match_parent"
        android:layout_above="@id/bottomFragmentLayout"
        android:layout_toRightOf="@id/menuLayout"
        android:visibility="invisible" >

    </RelativeLayout>

    <RelativeLayout
        android:id="@+id/whereLayout"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_above="@id/bottomFragmentLayout"
        android:layout_toRightOf="@id/menuLayout"
        android:visibility="invisible" >

    </RelativeLayout>

</RelativeLayout>