No View Found for ID while adding fragment even though findViewById returns fine

1

I am getting this error while adding a fragment to GridLayout. The method getFieldContainer searches an existing layout or inflates a new one for the category name and then returns its GridLayout container. findViewById returns a valid layout but still fragment is unable to find the view with the same id

 @Override
protected void onPostCreate(@Nullable Bundle savedInstanceState) {
    super.onPostCreate(savedInstanceState);

    for (FormField field :
            AppState.getInstance().FormStep.Fields) {
        ArrayList<String> options = new ArrayList<>();
        for (FormField child :
                field.ChildFields) {
            options.add(child.FieldName);
        }
        if (field.Type != null) {
            Fragment fr = FormFieldFragment.newInstance(field);
            ViewGroup container = rootCategory.getFieldContainer(field.Category, rootCategory);
            if(findViewById(container.getId()) != null) {

                Log.e("FormActivity: ", "Container found");

                container.setId(View.generateViewId());
                getSupportFragmentManager().beginTransaction()
                        .replace(container.getId(), fr, "field").commit();
            }
            else {
                Log.e("FormActivity: ", "Container not found");
            }
        }
        else {
            Log.e("Error: ", "Field type null : " + field.FieldName);
        }
    }
}


    10-13 10:30:21.902 30332-30336/com.hisdu.emrintegratedmodules I/art: After code cache collection, code=209KB, data=142KB
10-13 10:30:22.051 30332-30336/com.hisdu.emrintegratedmodules I/art: Do partial code cache collection, code=250KB, data=179KB
10-13 10:30:22.051 30332-30336/com.hisdu.emrintegratedmodules I/art: After code cache collection, code=250KB, data=179KB
10-13 10:30:22.051 30332-30336/com.hisdu.emrintegratedmodules I/art: Increasing code cache capacity to 1024KB
10-13 10:30:26.583 30332-30391/com.hisdu.emrintegratedmodules D/EGL_emulation: eglMakeCurrent: 0xa5005120: ver 3 1 (tinfo 0xa50036a0)
10-13 10:30:28.731 30332-30332/com.hisdu.emrintegratedmodules E/FormActivity:: Container found
10-13 10:30:28.734 30332-30332/com.hisdu.emrintegratedmodules E/FormActivity:: Container found
10-13 10:30:28.735 30332-30332/com.hisdu.emrintegratedmodules E/FormActivity:: Container found
10-13 10:30:28.735 30332-30332/com.hisdu.emrintegratedmodules E/FormActivity:: Container found
10-13 10:30:28.735 30332-30332/com.hisdu.emrintegratedmodules E/FormActivity:: Container found
10-13 10:30:28.735 30332-30332/com.hisdu.emrintegratedmodules E/FormActivity:: Container found
10-13 10:30:28.735 30332-30332/com.hisdu.emrintegratedmodules E/FormActivity:: Container found
10-13 10:30:28.737 30332-30332/com.hisdu.emrintegratedmodules E/FormActivity:: Container found
10-13 10:30:28.737 30332-30332/com.hisdu.emrintegratedmodules E/FormActivity:: Container found
10-13 10:30:28.737 30332-30332/com.hisdu.emrintegratedmodules E/FormActivity:: Container found
10-13 10:30:28.737 30332-30332/com.hisdu.emrintegratedmodules E/FormActivity:: Container found
10-13 10:30:28.738 30332-30332/com.hisdu.emrintegratedmodules E/FormActivity:: Container found
10-13 10:30:28.738 30332-30332/com.hisdu.emrintegratedmodules E/FormActivity:: Container found
10-13 10:30:28.738 30332-30332/com.hisdu.emrintegratedmodules E/FormActivity:: Container found
10-13 10:30:28.738 30332-30332/com.hisdu.emrintegratedmodules E/FormActivity:: Container found
10-13 10:30:28.738 30332-30332/com.hisdu.emrintegratedmodules E/FormActivity:: Container found
10-13 10:30:28.739 30332-30332/com.hisdu.emrintegratedmodules W/ResourceType: No package identifier when getting name for resource number 0x00000001
10-13 10:30:28.740 30332-30332/com.hisdu.emrintegratedmodules E/FragmentManager: No view found for id 0x1 (unknown) for fragment FormFieldFragment{c8cd81c #0 id=0x1 field}
10-13 10:30:28.740 30332-30332/com.hisdu.emrintegratedmodules E/FragmentManager: Activity state:
10-13 10:30:28.740 30332-30332/com.hisdu.emrintegratedmodules D/FragmentManager:   Local FragmentActivity adeeed5 State:
10-13 10:30:28.741 30332-30332/com.hisdu.emrintegratedmodules D/FragmentManager:     mCreated=truemResumed=true mStopped=false mReallyStopped=false
10-13 10:30:28.741 30332-30332/com.hisdu.emrintegratedmodules D/FragmentManager:     mLoadersStarted=true
10-13 10:30:28.741 30332-30332/com.hisdu.emrintegratedmodules D/FragmentManager:   Active Fragments in 59df5a1:
10-13 10:30:28.741 30332-30332/com.hisdu.emrintegratedmodules D/FragmentManager:     #0: FormFieldFragment{c8cd81c #0 id=0x1 field}
10-13 10:30:28.741 30332-30332/com.hisdu.emrintegratedmodules D/FragmentManager:       mFragmentId=#1 mContainerId=#1 mTag=field
10-13 10:30:28.742 30332-30332/com.hisdu.emrintegratedmodules D/FragmentManager:       mState=1 mIndex=0 mWho=android:fragment:0 mBackStackNesting=0
10-13 10:30:28.742 30332-30332/com.hisdu.emrintegratedmodules D/FragmentManager:       mAdded=true mRemoving=false mFromLayout=false mInLayout=false
10-13 10:30:28.742 30332-30332/com.hisdu.emrintegratedmodules D/FragmentManager:       mHidden=false mDetached=false mMenuVisible=true mHasMenu=false
10-13 10:30:28.742 30332-30332/com.hisdu.emrintegratedmodules D/FragmentManager:       mRetainInstance=false mRetaining=false mUserVisibleHint=true
10-13 10:30:28.742 30332-30332/com.hisdu.emrintegratedmodules D/FragmentManager:       mFragmentManager=FragmentManager{59df5a1 in HostCallbacks{9ed3c6}}
10-13 10:30:28.743 30332-30332/com.hisdu.emrintegratedmodules D/FragmentManager:       mHost=android.support.v4.app.FragmentActivity$HostCallbacks@9ed3c6
10-13 10:30:28.743 30332-30332/com.hisdu.emrintegratedmodules D/FragmentManager:       mArguments=Bundle[{param1=Visits, param2=2, param3=[First visit, First revisit, Second revisit]}]
10-13 10:30:28.743 30332-30332/com.hisdu.emrintegratedmodules D/FragmentManager:   Added Fragments:
10-13 10:30:28.743 30332-30332/com.hisdu.emrintegratedmodules D/FragmentManager:     #0: FormFieldFragment{c8cd81c #0 id=0x1 field}
10-13 10:30:28.743 30332-30332/com.hisdu.emrintegratedmodules D/FragmentManager:   FragmentManager misc state:
10-13 10:30:28.743 30332-30332/com.hisdu.emrintegratedmodules D/FragmentManager:     mHost=android.support.v4.app.FragmentActivity$HostCallbacks@9ed3c6
10-13 10:30:28.743 30332-30332/com.hisdu.emrintegratedmodules D/FragmentManager:     mContainer=android.support.v4.app.FragmentActivity$HostCallbacks@9ed3c6
10-13 10:30:28.744 30332-30332/com.hisdu.emrintegratedmodules D/FragmentManager:     mCurState=4 mStateSaved=false mDestroyed=false
10-13 10:30:28.744 30332-30332/com.hisdu.emrintegratedmodules D/FragmentManager:   View Hierarchy:
10-13 10:30:28.744 30332-30332/com.hisdu.emrintegratedmodules D/FragmentManager:     com.android.internal.policy.DecorView{94aaf87 V.E..... ... 0,0-0,0}
10-13 10:30:28.744 30332-30332/com.hisdu.emrintegratedmodules D/FragmentManager:       android.widget.LinearLayout{fb20eb4 V.E..... ... 0,0-0,0}
10-13 10:30:28.745 30332-30332/com.hisdu.emrintegratedmodules D/FragmentManager:         android.view.ViewStub{2834add G.E..... ... 0,0-0,0 #10203ef android:id/action_mode_bar_stub}
10-13 10:30:28.745 30332-30332/com.hisdu.emrintegratedmodules D/FragmentManager:         android.widget.FrameLayout{6a46652 V.E..... ... 0,0-0,0}
10-13 10:30:28.745 30332-30332/com.hisdu.emrintegratedmodules D/FragmentManager:           android.support.v7.widget.ActionBarOverlayLayout{98bd23 V.E..... ... 0,0-0,0 #7f0d0073 app:id/decor_content_parent}
10-13 10:30:28.745 30332-30332/com.hisdu.emrintegratedmodules D/FragmentManager:             android.support.v7.widget.ContentFrameLayout{6bb6220 V.E..... ... 0,0-0,0 #1020002 android:id/content}
10-13 10:30:28.746 30332-30332/com.hisdu.emrintegratedmodules D/FragmentManager:               android.widget.LinearLayout{a6eb7d9 V.E..... ... 0,0-0,0}
10-13 10:30:28.746 30332-30332/com.hisdu.emrintegratedmodules D/FragmentManager:                 android.widget.ScrollView{7fe959e VFED.V.. ... 0,0-0,0}
10-13 10:30:28.746 30332-30332/com.hisdu.emrintegratedmodules D/FragmentManager:                   android.widget.LinearLayout{f30087f V.E..... ... 0,0-0,0}
10-13 10:30:28.746 30332-30332/com.hisdu.emrintegratedmodules D/FragmentManager:                     android.widget.LinearLayout{b44804c V.E..... ... 0,0-0,0 #7f0d0084 app:id/formActivity_frgContainer}
10-13 10:30:28.747 30332-30332/com.hisdu.emrintegratedmodules D/FragmentManager:                       android.widget.LinearLayout{209f895 V.E..... ... 0,0-0,0}
10-13 10:30:28.747 30332-30332/com.hisdu.emrintegratedmodules D/FragmentManager:                         android.widget.LinearLayout{3a6daa V.E..... ... 0,0-0,0}
10-13 10:30:28.747 30332-30332/com.hisdu.emrintegratedmodules D/FragmentManager:                           android.support.v7.widget.AppCompatTextView{1c6ad9b V.ED.... ... 0,0-0,0}
10-13 10:30:28.747 30332-30332/com.hisdu.emrintegratedmodules D/FragmentManager:                           android.support.v7.widget.AppCompatTextView{b5f5538 V.ED.... ... 0,0-0,0 #7f0d00a8 app:id/formLayout_category_tvCategoryName}
10-13 10:30:28.747 30332-30332/com.hisdu.emrintegratedmodules D/FragmentManager:                           android.view.View{4de8911 V.ED.... ... 0,0-0,0}
10-13 10:30:28.748 30332-30332/com.hisdu.emrintegratedmodules W/ResourceType: No package identifier when getting name for resource number 0x00000010
10-13 10:30:28.748 30332-30332/com.hisdu.emrintegratedmodules D/FragmentManager:                         android.widget.GridLayout{4a9ba76 V.E..... ... 0,0-0,0 #10}
10-13 10:30:28.748 30332-30332/com.hisdu.emrintegratedmodules D/FragmentManager:                           android.widget.LinearLayout{588877 V.E..... ... 0,0-0,0}
10-13 10:30:28.748 30332-30332/com.hisdu.emrintegratedmodules D/FragmentManager:                             android.widget.LinearLayout{2508ce4 V.E..... ... 0,0-0,0}
10-13 10:30:28.748 30332-30332/com.hisdu.emrintegratedmodules D/FragmentManager:                               android.support.v7.widget.AppCompatTextView{391a54d V.ED.... ... 0,0-0,0}
10-13 10:30:28.749 30332-30332/com.hisdu.emrintegratedmodules D/FragmentManager:                               android.support.v7.widget.AppCompatTextView{bef0802 V.ED.... ... 0,0-0,0 #7f0d00a8 app:id/formLayout_category_tvCategoryName}
10-13 10:30:28.749 30332-30332/com.hisdu.emrintegratedmodules D/FragmentManager:                               android.view.View{cc33513 V.ED.... ... 0,0-0,0}
10-13 10:30:28.749 30332-30332/com.hisdu.emrintegratedmodules W/ResourceType: No package identifier when getting name for resource number 0x0000000f
10-13 10:30:28.750 30332-30332/com.hisdu.emrintegratedmodules D/FragmentManager:                             android.widget.GridLayout{8fb9350 V.E..... ... 0,0-0,0 #f}
10-13 10:30:28.750 30332-30332/com.hisdu.emrintegratedmodules D/FragmentManager:                           android.widget.LinearLayout{9e04949 V.E..... ... 0,0-0,0}
10-13 10:30:28.750 30332-30332/com.hisdu.emrintegratedmodules D/FragmentManager:                             android.widget.LinearLayout{249a24e V.E..... ... 0,0-0,0}
10-13 10:30:28.750 30332-30332/com.hisdu.emrintegratedmodules D/FragmentManager:                               android.support.v7.widget.AppCompatTextView{f220f6f V.ED.... ... 0,0-0,0}
10-13 10:30:28.751 30332-30332/com.hisdu.emrintegratedmodules D/FragmentManager:                               android.support.v7.widget.AppCompatTextView{10e947c V.ED.... ... 0,0-0,0 #7f0d00a8 app:id/formLayout_category_tvCategoryName}
10-13 10:30:28.751 30332-30332/com.hisdu.emrintegratedmodules D/FragmentManager:                               android.view.View{85b3105 V.ED.... ... 0,0-0,0}
10-13 10:30:28.751 30332-30332/com.hisdu.emrintegratedmodules W/ResourceType: No package identifier when getting name for resource number 0x00000009
10-13 10:30:28.751 30332-30332/com.hisdu.emrintegratedmodules D/FragmentManager:                             android.widget.GridLayout{6a1955a V.E..... ... 0,0-0,0 #9}
10-13 10:30:28.752 30332-30332/com.hisdu.emrintegratedmodules D/FragmentManager:                     android.support.v7.widget.AppCompatButton{bea338b VFED..C. ... 0,0-0,0 #7f0d0085 app:id/formActivity_btnSubmit}
10-13 10:30:28.752 30332-30332/com.hisdu.emrintegratedmodules D/FragmentManager:             android.support.v7.widget.ActionBarContainer{6ee7c68 V.ED.... ... 0,0-0,0 #7f0d0074 app:id/action_bar_container}
10-13 10:30:28.752 30332-30332/com.hisdu.emrintegratedmodules D/FragmentManager:               android.support.v7.widget.Toolbar{de2d881 V.E..... ... 0,0-0,0 #7f0d0075 app:id/action_bar}
10-13 10:30:28.753 30332-30332/com.hisdu.emrintegratedmodules D/FragmentManager:                 android.support.v7.widget.AppCompatTextView{c53ad26 V.ED.... ... 0,0-0,0}
10-13 10:30:28.753 30332-30332/com.hisdu.emrintegratedmodules D/FragmentManager:               android.support.v7.widget.ActionBarContextView{fc67d67 G.E..... ... 0,0-0,0 #7f0d0076 app:id/action_context_bar}
10-13 10:30:28.753 30332-30332/com.hisdu.emrintegratedmodules D/AndroidRuntime: Shutting down VM
10-13 10:30:28.758 30332-30332/com.hisdu.emrintegratedmodules E/AndroidRuntime: FATAL EXCEPTION: main
                                                                                Process: com.hisdu.emrintegratedmodules, PID: 30332
                                                                                java.lang.RuntimeException: Unable to resume activity {com.hisdu.emrintegratedmodules/com.hisdu.emrintegratedmodules.Activities.FormActivity}: java.lang.IllegalArgumentException: No view found for id 0x1 (unknown) for fragment FormFieldFragment{c8cd81c #0 id=0x1 field}
                                                                                    at android.app.ActivityThread.performResumeActivity(ActivityThread.java:3429)
                                                                                    at android.app.ActivityThread.handleResumeActivity(ActivityThread.java:3469)
                                                                                    at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2732)
                                                                                    at android.app.ActivityThread.-wrap12(ActivityThread.java)
                                                                                    at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1477)
                                                                                    at android.os.Handler.dispatchMessage(Handler.java:102)
                                                                                    at android.os.Looper.loop(Looper.java:154)
                                                                                    at android.app.ActivityThread.main(ActivityThread.java:6119)
                                                                                    at java.lang.reflect.Method.invoke(Native Method)
                                                                                    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:886)
                                                                                    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:776)
                                                                                 Caused by: java.lang.IllegalArgumentException: No view found for id 0x1 (unknown) for fragment FormFieldFragment{c8cd81c #0 id=0x1 field}
                                                                                    at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:1293)
                                                                                    at android.support.v4.app.FragmentManagerImpl.moveFragmentToExpectedState(FragmentManager.java:1528)
                                                                                    at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:1595)
                                                                                    at android.support.v4.app.BackStackRecord.executeOps(BackStackRecord.java:758)
                                                                                    at android.support.v4.app.FragmentManagerImpl.executeOps(FragmentManager.java:2363)
                                                                                    at android.support.v4.app.FragmentManagerImpl.executeOpsTogether(FragmentManager.java:2149)
                                                                                    at android.support.v4.app.FragmentManagerImpl.optimizeAndExecuteOps(FragmentManager.java:2103)
                                                                                    at android.support.v4.app.FragmentManagerImpl.execPendingActions(FragmentManager.java:2013)
                                                                                    at android.support.v4.app.FragmentController.execPendingActions(FragmentController.java:388)
                                                                                    at android.support.v4.app.FragmentActivity.onResume(FragmentActivity.java:488)
                                                                                    at android.app.Instrumentation.callActivityOnResume(Instrumentation.java:1269)
                                                                                    at android.app.Activity.performResume(Activity.java:6783)
                                                                                    at android.app.ActivityThread.performResumeActivity(ActivityThread.java:3406)
                                                                                    at android.app.ActivityThread.handleResumeActivity(ActivityThread.java:3469) 
                                                                                    at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2732) 
                                                                                    at android.app.ActivityThread.-wrap12(ActivityThread.java) 
                                                                                    at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1477) 
                                                                                    at android.os.Handler.dispatchMessage(Handler.java:102) 
                                                                                    at android.os.Looper.loop(Looper.java:154) 
                                                                                    at android.app.ActivityThread.main(ActivityThread.java:6119) 
                                                                                    at java.lang.reflect.Method.invoke(Native Method) 
                                                                                    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:886) 
                                                                                    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:776) 
android
android-fragments
asked on Stack Overflow Oct 13, 2017 by Hassaan Akbar

0 Answers

Nobody has answered this question yet.


User contributions licensed under CC BY-SA 3.0