Android开放片段从活性没有视图找到ID 0x7f0(com.pakagename:ID/flLoginMainLayout),用于片段OpenFragmentName {AnotherFragment}

问题描述:

登录活动Android开放片段从活性没有视图找到ID 0x7f0(com.pakagename:ID/flLoginMainLayout),用于片段OpenFragmentName {AnotherFragment}

fragmentTransaction.add(R.id.flLoginMainLayout, 
OpenFragmentName, AppConstants.tag_prev_list_fragment); 

它给我错误以下错误

E/UncaughtException:java.lang.IllegalArgumentException异常:(:ID/flLoginMainLayout com.doctorstay),用于片段OpenFragmentName {4450afc0#1的id = 0x7f0f0113 AnotherFragment}

我还用Diff容器调用相同的代码在AnotherFragment未发现ID 0x7f0f0113视图ID

((AnotherFragment) fragment).addFragment(R.id.flMainLayout, 
           OpenFragmentName, AppConstants.tag_prev_list_fragment); 

XML布局:activity_login_fragment(用途是flLoginMainLayout)

<?xml version="1.0" encoding="utf-8"?> 
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    xmlns:tools="http://schemas.android.com/tools" 
    android:id="@+id/flLoginMainLayout" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    tools:context="com.pakagename.pakagename2.OpenFragmentName"> 

</FrameLayout> 

XML对于登录布局:activity_login(用途是flLoginMainLayout)

<?xml version="1.0" encoding="utf-8"?> 
<FrameLayout 
    xmlns:android="http://schemas.android.com/apk/res/android" 
    xmlns:app="http://schemas.android.com/apk/res-auto" 
    xmlns:tools="http://schemas.android.com/tools" 
    android:id="@+id/flRootLogin" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    tools:context="com.pakagename.LoginActivity"> 
+0

请发布您的布局代码 –

问题的观点,美有用膨胀片段

确保视图是正确的布局

  • 此异常也可能发生如果正在膨胀等 布局存在哪些要传递给 FragmentTransaction.replace(INT ID,片段)布局ID指定。确保布局ID是唯一的 它应该工作。