No view found for id for fragment
12,619
Here container is your ViewGroup
, So, container dosen't have your faragment_add
, fragment_quick_facts.xml
only has it now and which acts as your view
currently.
So please change
detailText= (TextView) container.findViewById(R.id.fragment_add);
to
detailText= (TextView) view.findViewById(R.id.fragment_add);
And also look
fragmentTransaction.replace(R.id.fragment_quickfacts, fragment);
You are trying to replace fragment_quickfacts
, which is in your fragment_quick_facts.xml
not in fragment_detail.xml
. So check it also or post your fragment_detail.xml
too.
If you are not clear, then please go through Building a Dynamic UI with Fragments
Author by
rahul
Updated on June 04, 2022Comments
-
rahul over 1 year
i am very much confused by this error ,what i am doing is that trying to replace the fragment within a DetailActivity which is DetailActivityFragment which got replaced onclick by the QuickFacts fragment
public class DetailActivityFragment extends Fragment{ TextView textView; ImageView imageView; TextView details; Button button; public DetailActivityFragment() { } @Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { View view=inflater.inflate(R.layout.fragment_detail, container, false); Bundle getBundle = getActivity().getIntent().getExtras(); String name = getBundle.getString("NAME"); textView= (TextView) view.findViewById(R.id.bioname); textView.setText(name); imageView= (ImageView) view.findViewById(R.id.imageView); imageView.setImageResource(getBundle.getInt("IMAGE")); Log.v("test", "images are coming"); button= (Button) view.findViewById(R.id.button_quickfacts); button.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { Fragment fragment = new QuickFacts(); FragmentTransaction fragmentTransaction = getFragmentManager().beginTransaction(); fragmentTransaction.replace(R.id.fragment_quickfacts, fragment); fragmentTransaction.setTransition(FragmentTransaction.TRANSIT_FRAGMENT_FADE); fragmentTransaction.addToBackStack(null); fragmentTransaction.commit(); } }); return view; } }
my quickfacts fragment
public class QuickFacts extends Fragment { TextView detailText; @Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { // Inflate the layout for this fragment View view=inflater.inflate(R.layout.fragment_quick_facts, container, false); Bundle getBundle = getActivity().getIntent().getExtras(); String details=getBundle.getString("DETAIL"); detailText= (TextView) container.findViewById(R.id.fragment_add); detailText.setText(details); return view; } }
fragment_quick_facts.xml
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" android:layout_height="match_parent" android:id="@+id/fragment_quickfacts" tools:context="com.example.rahul.famousbiography.fragments.QuickFacts"> <!-- TODO: Update blank fragment layout --> <TextView android:layout_width="match_parent" android:layout_height="match_parent" android:text="@string/hello_blank_fragment" android:id="@+id/fragment_add" /> </FrameLayout>
my logcat
FATAL EXCEPTION: main Process: com.example.rahul.famousbiography, PID: 11751 java.lang.IllegalArgumentException: No view found for id 0x7f0c007d (com.example.rahul.famousbiography:id/fragment_quickfacts) for fragment QuickFacts{2ff08f2b #1 id=0x7f0c007d} at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:1059) at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:1248) at android.support.v4.app.BackStackRecord.run(BackStackRecord.java:738) at android.support.v4.app.FragmentManagerImpl.execPendingActions(FragmentManager.java:1613) at android.support.v4.app.FragmentManagerImpl$1.run(FragmentManager.java:517) at android.os.Handler.handleCallback(Handler.java:739) at android.os.Handler.dispatchMessage(Handler.java:95) at android.os.Looper.loop(Looper.java:135) at android.app.ActivityThread.main(ActivityThread.java:5254) at java.lang.reflect.Method.invoke(Native Method) at java.lang.reflect.Method.invoke(Method.java:372) at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:903) at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:698
-
Ajay Pandya almost 8 yearspaste logacat please
-
-
rahul almost 8 yearsfragment_quickfacts is a framelayout of fragment_quick_facts.xml which is layout for quickfacts fragment and in the detail fragment i have one button which got clicked and replace by quickfacts fragment