Can not replace fragment. No view found for id for fragment
Solution 1
Activity from which I wanted to open Fragment had fragment defined in XML file. To replace fragment, fragment have to be defined programmatically
Solution 2
It seems you're using different fragment id in the code and in the Activity layout's FrameLayout id. In the code, you're using "map_container" fragment id, but the stacktrace says:
No view found for id 0x7f050013 (com.urbanforms.main:id/fragment_container) for fragment ArticleMuralFragment
Are you sure you're using the same fragment id? Because i come to the same problem when doing so. Hope this helps :)
Solution 3
You are trying to put a fragment into a view container with id: fragment_container here:
FragmentTransaction transaction = getSupportFragmentManager()
.beginTransaction();
transaction.replace(R.id.fragment_container,
newElement);
But you likely have no view with that id. Find the container view that you want this fragment to go into and give it the android:id="@+id/fragment_container tag
Comments
-
Serafins almost 2 years
I have list of fragments and artice. Every lelement on list is connected with article. That works fine. But when I try replace article by ID from external activity I have an error:
No view found for id for fragment
External Activity:
ArticleMuralFragment newElement = new ArticleMuralFragment(); Bundle args = new Bundle(); args.putInt("ARG_POSITION", 7); newElement.setArguments(args); FragmentTransaction transaction = getSupportFragmentManager().beginTransaction(); transaction.replace(R.id.map_container, newElement); transaction.addToBackStack(null); transaction.commit();
XML ArticleFragment
LogCat
12-10 20:05:28.866: E/FragmentManager(18952): No view found for id 0x7f050013 (com.urbanforms.main:id/fragment_container) for fragment ArticleMuralFragment{423009f8 #0 id=0x7f050013} 12-10 20:05:28.866: E/FragmentManager(18952): Activity state: 12-10 20:05:28.876: D/FragmentManager(18952): Local FragmentActivity 41fb0db0 State: 12-10 20:05:28.876: D/FragmentManager(18952): mCreated=truemResumed=true mStopped=false mReallyStopped=false 12-10 20:05:28.876: D/FragmentManager(18952): mLoadersStarted=true 12-10 20:05:28.876: D/FragmentManager(18952): Active Fragments in 41fb1e58: 12-10 20:05:28.876: D/FragmentManager(18952): #0: ArticleMuralFragment{423009f8 #0 id=0x7f050013} 12-10 20:05:28.876: D/FragmentManager(18952): mFragmentId=#7f050013 mContainerId=#7f050013 mTag=null 12-10 20:05:28.876: D/FragmentManager(18952): mState=0 mIndex=0 mWho=android:fragment:0 mBackStackNesting=1 12-10 20:05:28.876: D/FragmentManager(18952): mAdded=true mRemoving=false mResumed=false mFromLayout=false mInLayout=false 12-10 20:05:28.876: D/FragmentManager(18952): mHidden=false mDetached=false mMenuVisible=true mHasMenu=false 12-10 20:05:28.876: D/FragmentManager(18952): mRetainInstance=false mRetaining=false mUserVisibleHint=true 12-10 20:05:28.876: D/FragmentManager(18952): mFragmentManager=FragmentManager{41fb1e58 in Map{41fb0db0}} 12-10 20:05:28.876: D/FragmentManager(18952): mActivity=com.urbanforms.main.map.Map@41fb0db0 12-10 20:05:28.876: D/FragmentManager(18952): mArguments=Bundle[{ARG_POSITION=7}] 12-10 20:05:28.876: D/FragmentManager(18952): Added Fragments: 12-10 20:05:28.876: D/FragmentManager(18952): #0: ArticleMuralFragment{423009f8 #0 id=0x7f050013} 12-10 20:05:28.876: D/FragmentManager(18952): Back Stack Indices: 12-10 20:05:28.876: D/FragmentManager(18952): #0: BackStackEntry{423016c0 #0} 12-10 20:05:28.876: D/FragmentManager(18952): FragmentManager misc state: 12-10 20:05:28.876: D/FragmentManager(18952): mActivity=com.urbanforms.main.map.Map@41fb0db0 12-10 20:05:28.886: D/FragmentManager(18952): mContainer=android.support.v4.app.FragmentActivity$2@41fb2760 12-10 20:05:28.886: D/FragmentManager(18952): mCurState=5 mStateSaved=false mDestroyed=false 12-10 20:05:28.886: D/FragmentManager(18952): View Hierarchy: 12-10 20:05:28.886: D/FragmentManager(18952): com.android.internal.policy.impl.PhoneWindow$DecorView{41fb3958 V.E..... ... 0,0-1280,736} 12-10 20:05:28.886: D/FragmentManager(18952): com.android.internal.widget.ActionBarOverlayLayout{41fb3fd0 V.ED.... ... 0,0-1280,736 #1020310 android:id/action_bar_overlay_layout} 12-10 20:05:28.886: D/FragmentManager(18952): android.widget.FrameLayout{41fb4bd8 V.E..... ... 0,108-1280,736 #1020002 android:id/content} 12-10 20:05:28.886: D/FragmentManager(18952): android.widget.RelativeLayout{41fbaa70 V.E..... ... 0,0-1280,628} 12-10 20:05:28.886: D/FragmentManager(18952): android.widget.FrameLayout{41fbea10 V.E..... ... 0,0-1280,628 #7f050014 app:id/map} 12-10 20:05:28.886: D/FragmentManager(18952): android.widget.FrameLayout{41f75178 V.E..... ... 0,0-1280,628} 12-10 20:05:28.886: D/FragmentManager(18952): maps.ae.i{41f7ebf0 VFED..C. ... 0,0-1280,628} 12-10 20:05:28.886: D/FragmentManager(18952): android.widget.RelativeLayout{41fffc58 V.E..... ... 0,0-1280,628} 12-10 20:05:28.886: D/FragmentManager(18952): android.widget.ImageView{41ffebf0 V.ED.... ... 7,593-82,621} 12-10 20:05:28.886: D/FragmentManager(18952): android.widget.RelativeLayout{41f86af0 V.E..... ... 0,0-1280,628} 12-10 20:05:28.886: W/ResourceType(18952): No package identifier when getting name for resource number 0x00000002 12-10 20:05:28.886: D/FragmentManager(18952): android.view.View{42050988 V.ED..C. ... 1211,13-1267,69 #2} 12-10 20:05:28.886: W/ResourceType(18952): No package identifier when getting name for resource number 0x00000003 12-10 20:05:28.886: D/FragmentManager(18952): android.widget.RelativeLayout{41ff3180 V.E..... ... 1267,82-1267,489 #3} 12-10 20:05:28.886: D/FragmentManager(18952): maps.bu.a{4205c660 G.ED..C. ... 0,0-0,0} 12-10 20:05:28.886: W/ResourceType(18952): No package identifier when getting name for resource number 0x00000001 12-10 20:05:28.886: D/FragmentManager(18952): android.widget.LinearLayout{42047d70 V.E..... ... 1211,502-1267,608 #1} 12-10 20:05:28.886: D/FragmentManager(18952): android.view.View{4205eba8 V.ED..C. ... 0,0-56,53} 12-10 20:05:28.886: D/FragmentManager(18952): android.view.View{4204b6f8 V.ED..C. ... 0,53-56,106} 12-10 20:05:28.896: D/FragmentManager(18952): com.android.internal.widget.ActionBarContainer{41fb4fd0 V.ED.... ... 0,33-1280,108 #1020311 android:id/action_bar_container} 12-10 20:05:28.896: D/FragmentManager(18952): com.android.internal.widget.ActionBarView{41fb54d0 V.E..... ... 0,0-1280,75 #1020312 android:id/action_bar} 12-10 20:05:28.896: D/FragmentManager(18952): android.widget.LinearLayout{41fb5a38 VFE...C. ... 0,0-210,75} 12-10 20:05:28.896: D/FragmentManager(18952): com.android.internal.widget.ActionBarView$HomeView{41fb6ab8 V.E..... ... 0,0-65,75} 12-10 20:05:28.896: D/FragmentManager(18952): android.widget.ImageView{41fb6e48 V.ED.... ... 0,27-21,48 #102025a android:id/up} 12-10 20:05:28.896: D/FragmentManager(18952): android.widget.ImageView{41fb71a0 V.ED.... ... 17,16-60,59 #102002c android:id/home} 12-10 20:05:28.896: D/FragmentManager(18952): android.widget.LinearLayout{41fb8370 V.E..... ... 65,21-210,54} 12-10 20:05:28.896: D/FragmentManager(18952): android.widget.TextView{41fb8680 V.ED.... ... 0,0-134,33 #1020264 android:id/action_bar_title} 12-10 20:05:28.896: D/FragmentManager(18952): android.widget.TextView{41fb9300 G.ED.... ... 0,0-0,0 #1020265 android:id/action_bar_subtitle} 12-10 20:05:28.896: D/FragmentManager(18952): com.android.internal.view.menu.ActionMenuView{41ff6690 V.ED.... ... 1280,0-1280,75} 12-10 20:05:28.896: D/FragmentManager(18952): com.android.internal.widget.ActionBarContextView{41fb98d8 G.E..... ... 0,0-0,0 #1020313 android:id/action_context_bar} 12-10 20:05:28.896: D/FragmentManager(18952): com.android.internal.widget.ActionBarContainer{41fb9da0 G.ED.... ... 0,0-0,0 #1020314 android:id/split_action_bar} 12-10 20:05:28.896: D/AndroidRuntime(18952): Shutting down VM 12-10 20:05:28.896: W/dalvikvm(18952): threadid=1: thread exiting with uncaught exception (group=0x41801b90) 12-10 20:05:28.906: E/AndroidRuntime(18952): FATAL EXCEPTION: main 12-10 20:05:28.906: E/AndroidRuntime(18952): Process: com.urbanforms.main, PID: 18952 12-10 20:05:28.906: E/AndroidRuntime(18952): java.lang.IllegalArgumentException: No view found for id 0x7f050013 (com.urbanforms.main:id/fragment_container) for fragment ArticleMuralFragment{423009f8 #0 id=0x7f050013} 12-10 20:05:28.906: E/AndroidRuntime(18952): at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:919) 12-10 20:05:28.906: E/AndroidRuntime(18952): at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:1104) 12-10 20:05:28.906: E/AndroidRuntime(18952): at android.support.v4.app.BackStackRecord.run(BackStackRecord.java:682) 12-10 20:05:28.906: E/AndroidRuntime(18952): at android.support.v4.app.FragmentManagerImpl.execPendingActions(FragmentManager.java:1467) 12-10 20:05:28.906: E/AndroidRuntime(18952): at android.support.v4.app.FragmentManagerImpl$1.run(FragmentManager.java:440) 12-10 20:05:28.906: E/AndroidRuntime(18952): at android.os.Handler.handleCallback(Handler.java:733) 12-10 20:05:28.906: E/AndroidRuntime(18952): at android.os.Handler.dispatchMessage(Handler.java:95) 12-10 20:05:28.906: E/AndroidRuntime(18952): at android.os.Looper.loop(Looper.java:137) 12-10 20:05:28.906: E/AndroidRuntime(18952): at android.app.ActivityThread.main(ActivityThread.java:4998) 12-10 20:05:28.906: E/AndroidRuntime(18952): at java.lang.reflect.Method.invokeNative(Native Method) 12-10 20:05:28.906: E/AndroidRuntime(18952): at java.lang.reflect.Method.invoke(Method.java:515) 12-10 20:05:28.906: E/AndroidRuntime(18952): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:777) 12-10 20:05:28.906: E/AndroidRuntime(18952): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:593) 12-10 20:05:28.906: E/AndroidRuntime(18952): at dalvik.system.NativeStart.main(Native Method)