title: java.lang.IllegalArgumentException: DrawerLayout must be measured with MeasureSpec.EXACTLY
body: <p>I searched a lot of questions , but none of the answers helped me ! I connected an activity with a navigation drawer to a fragment ... but I start from this mistake ! Thanks for your help!</p>
  
  <pre><code>java.lang.IllegalArgumentException: DrawerLayout must be measured with MeasureSpec.EXACTLY.
  </code></pre>
  
  <p>xml class</p>
  
  <pre><code>&lt;android.support.v4.widget.DrawerLayout
  xmlns:android="http://schemas.android.com/apk/res/android"
  xmlns:app="http://schemas.android.com/apk/res-auto"
  android:id="@+id/drawer_layout"
  android:layout_width="match_parent"
  android:layout_height="match_parent"
  android:layout_gravity="end"
  android:background="@color/colorAccent"&gt;
  &lt;include
      layout="@layout/app_bar_main"
      android:layout_width="match_parent"
      android:layout_height="match_parent" /&gt;
  
  
  
  &lt;!-- The main content view --&gt;
  
  &lt;FrameLayout
      android:id="@+id/content_frame"
      android:layout_width="match_parent"
      android:layout_height="match_parent"
      android:layout_marginTop="80dp"
      /&gt;
  
  &lt;!-- The navigation drawer --&gt;
  
  &lt;ListView
      android:id="@+id/drawer_list"
      android:layout_width="240dp"
      android:layout_height="match_parent"
      android:layout_gravity="right"
      android:background="#111"
      android:choiceMode="singleChoice"
      android:divider="@android:color/transparent"
      android:dividerHeight="0dp"
      android:paddingTop="80dp"/&gt;
  
      &lt;/android.support.v4.widget.DrawerLayout&gt;
  </code></pre>
  
  <p>hedline fragment</p>
  
  <pre><code>public class HeadlinesFragment extends ListFragment {
  
  String[] Headlines = {
          "Article One",
          "Article Two",
          "Article 3",
          "Article 4",
          "Article 5",
          "Article 6",
  };
  
  SearchView search_view;
  
  
  
  OnHeadlineSelectedListener mCallback;
  
  String[] menutitles;
  TypedArray menuIcons;
  
  CustomAdapter adapter;
  private List&lt;RowItem&gt; rowItems;
  
  // The container Activity must implement this interface so the frag can deliver messages
  public interface OnHeadlineSelectedListener {
      /** Called by HeadlinesFragment when a list item is selected */
      public void onArticleSelected(int position);
  }
  
  @Override
  public View onCreateView(LayoutInflater inflater, ViewGroup container,
                           Bundle savedInstanceState) {
      // We need to use a different list item layout for devices older than Honeycomb
      int layout = Build.VERSION.SDK_INT &gt;= Build.VERSION_CODES.HONEYCOMB ?
              android.R.layout.simple_list_item_activated_1 : android.R.layout.simple_list_item_1;
  
      return inflater.inflate(R.layout.list_fragment, null, false);
  
  
  
  
  
  
  
  
  
  
  
  }
  
  @Override
  public void onActivityCreated(Bundle savedInstanceState) {
  
      super.onActivityCreated(savedInstanceState);
  
      menutitles = getResources().getStringArray(R.array.titles);
      menuIcons = getResources().obtainTypedArray(R.array.icons);
  
      rowItems = new ArrayList&lt;RowItem&gt;();
  
      for (int i = 0; i &lt; menutitles.length; i++) {
          RowItem items = new RowItem(menutitles[i], menuIcons.getResourceId(
                  i, -1));
  
          rowItems.add(items);
      }
  
      adapter = new CustomAdapter(getActivity(), rowItems);
      setListAdapter(adapter);
  
  
  
  
  }
  
  
  
  
  @Override
  public void onStart() {
      super.onStart();
  
      // When in two-pane layout, set the listview to highlight the selected list item
      // (We do this during onStart because at the point the listview is available.)
      if (getFragmentManager().findFragmentById(R.id.article_fragment) != null) {
          getListView().setChoiceMode(ListView.CHOICE_MODE_SINGLE);
      }
  }
  
  @Override
  public void onAttach(Activity activity) {
      super.onAttach(activity);
  
      // This makes sure that the container activity has implemented
      // the callback interface. If not, it throws an exception.
      try {
          mCallback = (OnHeadlineSelectedListener) activity;
      } catch (ClassCastException e) {
          throw new ClassCastException(activity.toString()
                  + " must implement OnHeadlineSelectedListener");
      }
  }
  
  @Override
  public void onListItemClick(ListView l, View v, int position, long id) {
      // Notify the parent activity of selected item
      mCallback.onArticleSelected(position);
  
      // Set the item as checked to be highlighted when in two-pane layout
      getListView().setItemChecked(position, true);
  }
  </code></pre>
  
  <p>}</p>
  
  <p>main activity of fragment`</p>
  
  <pre><code>public class MainActivity_list extends FragmentActivity
      implements HeadlinesFragment.OnHeadlineSelectedListener {
  
  /** Called when the activity is first created. */
  @Override
  public void onCreate(Bundle savedInstanceState) {
      super.onCreate(savedInstanceState);
      setContentView(R.layout.news_articles);
  
      // Check whether the activity is using the layout version with
      // the fragment_container FrameLayout. If so, we must add the first fragment
      if (findViewById(R.id.fragment_container) != null) {
  
          // However, if we're being restored from a previous state,
          // then we don't need to do anything and should return or else
          // we could end up with overlapping fragments.
          if (savedInstanceState != null) {
              return;
          }
  
          // Create an instance of ExampleFragment
          HeadlinesFragment firstFragment = new HeadlinesFragment();
  
          // In case this activity was started with special instructions from an Intent,
          // pass the Intent's extras to the fragment as arguments
          firstFragment.setArguments(getIntent().getExtras());
  
          // Add the fragment to the 'fragment_container' FrameLayout
          getSupportFragmentManager().beginTransaction()
                  .add(R.id.fragment_container, firstFragment).commit();
      }
  }
  
  public void onArticleSelected(int position) {
      // The user selected the headline of an article from the HeadlinesFragment
  
      // Capture the article fragment from the activity layout
      ArticleFragment articleFrag = (ArticleFragment)
              getSupportFragmentManager().findFragmentById(R.id.article_fragment);
  
      if (articleFrag != null) {
          // If article frag is available, we're in two-pane layout...
  
          // Call a method in the ArticleFragment to update its content
          articleFrag.updateArticleView(position);
  
      } else {
          // If the frag is not available, we're in the one-pane layout and must swap frags...
  
          // Create fragment and give it an argument for the selected article
          ArticleFragment newFragment = new ArticleFragment();
          Bundle args = new Bundle();
          args.putInt(ArticleFragment.ARG_POSITION, position);
          newFragment.setArguments(args);
          FragmentTransaction transaction = getSupportFragmentManager().beginTransaction();
  
          // Replace whatever is in the fragment_container view with this fragment,
          // and add the transaction to the back stack so the user can navigate back
          transaction.replace(R.id.fragment_container, newFragment);
          transaction.addToBackStack(null);
  
          // Commit the transaction
          transaction.commit();
      }
  }
  </code></pre>
  
  <p>}</p>
  
  <p>article fragment.java</p>
  
  <pre><code>public class ArticleFragment extends Fragment {
  final static String ARG_POSITION = "position";
  int mCurrentPosition = -1;
  
  @Override
  public View onCreateView(LayoutInflater inflater, ViewGroup container,
      Bundle savedInstanceState) {
  
      // If activity recreated (such as from screen rotate), restore
      // the previous article selection set by onSaveInstanceState().
      // This is primarily necessary when in the two-pane layout.
      if (savedInstanceState != null) {
          mCurrentPosition = savedInstanceState.getInt(ARG_POSITION);
      }
  
      // Inflate the layout for this fragment
      return inflater.inflate(R.layout.activity_main, container, false);
  }
  
  @Override
  public void onStart() {
      super.onStart();
  
      // During startup, check if there are arguments passed to the fragment.
      // onStart is a good place to do this because the layout has already been
      // applied to the fragment at this point so we can safely call the method
      // below that sets the article text.
      Bundle args = getArguments();
      if (args != null) {
          // Set article based on argument passed in
          updateArticleView(args.getInt(ARG_POSITION));
      } else if (mCurrentPosition != -1) {
          // Set article based on saved instance state defined during onCreateView
          updateArticleView(mCurrentPosition);
      }
  }
  
  public void updateArticleView(int position) {
  
  
  
  }
  
  @Override
  public void onSaveInstanceState(Bundle outState) {
      super.onSaveInstanceState(outState);
  
      // Save the current article selection in case we need to recreate the fragment
      outState.putInt(ARG_POSITION, mCurrentPosition);
  }
  </code></pre>
  
  <p>}</p>
  
  <p>mainactivity.java (of navgation drawer)</p>
  
  <pre><code>public class MainActivity extends AppCompatActivity
      implements NavigationView.OnNavigationItemSelectedListener {
  
  String[] lista = {
          "Article One",
          "Article Two",
          "Article 3",
          "Article 4",
          "Article 5",
          "Article 6",
  };
  
  @Override
  protected void onCreate(Bundle savedInstanceState) {
      super.onCreate(savedInstanceState);
      setContentView(R.layout.activity_main);
      Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
  
  
      setSupportActionBar(toolbar);
  
  
  
  
  
  
      final DrawerLayout drawer = (DrawerLayout) findViewById(R.id.drawer_layout);
      ActionBarDrawerToggle toggle = new ActionBarDrawerToggle(this, drawer, R.string.navigation_drawer_open, R.string.navigation_drawer_close){
          @Override
          public boolean onOptionsItemSelected(MenuItem item) {
              // Handle action bar item clicks here. The action bar will
              // automatically handle clicks on the Home/Up button, so long
              // as you specify a parent activity in AndroidManifest.xml.
              int id = item.getItemId();
  
              //noinspection SimplifiableIfStatement
              if (id == R.id.btnMyMenu) {
  
                  if (drawer.isDrawerOpen(Gravity.RIGHT)) {
                      drawer.closeDrawer(Gravity.RIGHT);
                  } else {
                      drawer.openDrawer(Gravity.RIGHT);
                  }
                  return true;
              }
  
              return super.onOptionsItemSelected(item);
          }
      };
  
  
  
  
      drawer.setDrawerListener(toggle);
      toggle.syncState();
  
      Button btn=(Button) findViewById(R.id.button);
      btn.setOnClickListener(new View.OnClickListener() {
          @Override
          public void onClick(View v) {
              if (drawer.isDrawerOpen(Gravity.RIGHT)) {
                 drawer.closeDrawer(Gravity.RIGHT);
              } else {
                  drawer.openDrawer(Gravity.RIGHT);
              }
          }
      });
  
  
  
     ListView lv = (ListView) findViewById(R.id.drawer_list);
      // Convert ArrayList to array
  
      lv.setAdapter(new ArrayAdapter&lt;String&gt;(this, R.layout.list_menu,R.id.menu_text, lista));
  
      lv.setOnItemClickListener(new AdapterView.OnItemClickListener() {
          @Override
          public void onItemClick(AdapterView&lt;?&gt; parent, View view,
                                  int position, long id) {
              switch (position) {
                  case 0:
                      Intent activity0 = new Intent(MainActivity.this, pagina1.class);
                      startActivity(activity0);
                      break;
                  case 1:
                      Intent activity1 = new Intent(MainActivity.this, pagina1.class);
                      startActivity(activity1);
                      break;
  
  
              }
  
          }
  
          @SuppressWarnings("unused")
          public void onClick(View v) {
          }
  
          ;
      });
  
  }
  
  
  
  @Override
  public void onBackPressed() {
      DrawerLayout drawer = (DrawerLayout) findViewById(R.id.drawer_layout);
      if (drawer.isDrawerOpen(Gravity.RIGHT)) {
          drawer.closeDrawer(Gravity.RIGHT);
      } else {
          super.onBackPressed();
      }
  }
  
  @Override
  public boolean onCreateOptionsMenu(Menu menu) {
      int menuToUse = R.menu.my_right_side_menu;
  
      MenuInflater inflater = getMenuInflater();
      inflater.inflate(menuToUse, menu);
  
      // Inflate the menu; this adds items to the action bar if it is present.
      getMenuInflater().inflate(R.menu.main, menu);
      return true;
  }
  
  @Override
  public boolean onOptionsItemSelected(MenuItem item) {
      // Handle action bar item clicks here. The action bar will
      // automatically handle clicks on the Home/Up button, so long
      // as you specify a parent activity in AndroidManifest.xml.
      int id = item.getItemId();
  
      //noinspection SimplifiableIfStatement
      if (id == R.id.action_settings) {
          return true;
      }
  
      return super.onOptionsItemSelected(item);
  }
  
  @SuppressWarnings("StatementWithEmptyBody")
  @Override
  public boolean onNavigationItemSelected(MenuItem item) {
      // Handle navigation view item clicks here.
      int id = item.getItemId();
  
      if (id == R.id.nav_camera) {
          // Handle the camera action
      } else if (id == R.id.nav_gallery) {
  
      } else if (id == R.id.nav_slideshow) {
  
      } else if (id == R.id.nav_manage) {
  
      } else if (id == R.id.nav_share) {
  
      } else if (id == R.id.nav_send) {
  
      }
  
      DrawerLayout drawer = (DrawerLayout) findViewById(R.id.drawer_layout);
      drawer.closeDrawer(Gravity.RIGHT);
      return true;
  }
  </code></pre>
  
  <p>}</p>
  
  <p>there is also a rowitem.java, customadapeter.java</p>
  
  <p>app_bar.xml</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt;
  &lt;android.support.design.widget.CoordinatorLayout     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:layout_width="match_parent"
  android:layout_height="match_parent"
  android:fitsSystemWindows="true"
  tools:context="com.chiari.nicola.myapplication.MainActivity"&gt;
  
  &lt;android.support.design.widget.AppBarLayout
      android:layout_width="match_parent"
      android:layout_height="wrap_content"
      android:theme="@style/AppTheme.AppBarOverlay"&gt;
  
      &lt;android.support.v7.widget.Toolbar
          android:id="@+id/toolbar"
          android:layout_width="match_parent"
          android:layout_height="?attr/actionBarSize"
          android:background="?attr/colorPrimary"
          app:popupTheme="@style/AppTheme.PopupOverlay" /&gt;
  
  &lt;/android.support.design.widget.AppBarLayout&gt;
  
  &lt;include layout="@layout/content_main" /&gt;
  
  
  
  &lt;/android.support.design.widget.CoordinatorLayout&gt;
  </code></pre>
  
  <p>content_main.xml</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt;
  &lt;RelativeLayout 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:layout_width="match_parent"
  android:layout_height="match_parent"
  
  app:layout_behavior="@string/appbar_scrolling_view_behavior"
  tools:context="com.chiari.nicola.myapplication.MainActivity"
  tools:showIn="@layout/app_bar_main"&gt;
  
  &lt;TextView
      android:layout_width="wrap_content"
      android:layout_height="wrap_content"
      android:text="Hello World!" /&gt;
  &lt;Button
      android:layout_width="wrap_content"
      android:layout_height="wrap_content"
      android:id="@+id/button"/&gt;
  &lt;/RelativeLayout&gt;
  </code></pre>