hcnak hcnak - 1 year ago 96
Android Question

Error occurred in switching view in Fragment Navigation Drawer ,said no view found for fragment PlaceholderFragment

I had created a simple app via Android Studio using Navigation Drawer Fragment.

I was trying to show another view (like

) when user clicks an item of

So I use
public void onNavigationDrawerItemSelected(int position)
but when I run it, an error occurred :

FATAL EXCEPTION: mainProcess: com.akakanch.sample, PID: 28848
java.lang.IllegalArgumentException: No view found for id 0x7f0c0050 (com.akakanch.sample:id/container) for fragment PlaceholderFragment{250d0b42 #1 id=0x7f0c0050}

Here's my the only place I had change:


public void onNavigationDrawerItemSelected(int position) {
// update the main content by replacing fragments
FragmentManager fragmentManager = getSupportFragmentManager();
.replace(R.id.container, PlaceholderFragment.newInstance(position + 1))


So, how can I change the view correctly´╝č

Answer Source

it is because you are calling set content view from there. just set the layout you want to see as the layout of the fragment you are replacing and you will see it

inside the fragment:

public View onCreateView(LayoutInflater inflater, ViewGroup container,
                         Bundle savedInstanceState) {
          View view = inflater.inflate(R.layout.layout_about,container,false);  
      //do your fragment stuff 
      return view;

if you do this when you replace the fragment using fragment manager you will see the layout_about layout

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download