title: android:array index out of bound exception
body: <pre><code>import android.app.Activity;
  import android.app.Fragment;
  import android.app.FragmentManager;
  import android.content.res.Configuration;
  import android.content.res.TypedArray;
  import android.os.Bundle;
  import android.support.v4.widget.DrawerLayout;
  import android.support.v4.app.ActionBarDrawerToggle;
  import android.util.Log;
  import android.view.Menu;
  import android.view.MenuItem;
  import android.view.View;
  import android.widget.AdapterView;
  import android.widget.ListView;
  
  import java.util.ArrayList;
  
  public class MainActivity extends Activity {
      private DrawerLayout drawerLayout;
      private ListView lvSlidingMenu;
      private ActionBarDrawerToggle drawerToggle; // Navigation Drawer titles
      private CharSequence drawerTitle;
      private CharSequence appTitle;
  
      // Sliding Menu items
      private String[] titles;
      private TypedArray icons;
      private ArrayList slidingMenuItems;
      private SlidingMenuAdapter adapter;
  
      @Override
      protected void onCreate(Bundle savedInstanceState) {
          super.onCreate(savedInstanceState);
          setContentView(R.layout.activity_main);
          appTitle = drawerTitle = getTitle();
  
          // Load resources
          titles = getResources().getStringArray(R.array.nav_drawer_items);
          icons = getResources().obtainTypedArray(R.array.nav_drawer_icons);
  
          // Get Sliding Menu ListView istance
          drawerLayout = (DrawerLayout) findViewById(R.id.drawer_layout);
          lvSlidingMenu = (ListView) findViewById(R.id.lv_sliding_menu);
          slidingMenuItems = new ArrayList();
  
          // Creating and Adding SlidingMenuItems
          slidingMenuItems.add(new SlidingMenuItem(titles[0], icons.getResourceId(0,-1)));
          slidingMenuItems.add(new SlidingMenuItem(titles[1], icons.getResourceId(1, -1)));
          slidingMenuItems.add(new SlidingMenuItem(titles[2], icons.getResourceId(2, -1)));
          slidingMenuItems.add(new SlidingMenuItem(titles[3], icons.getResourceId(3, -1)));
  
          // Recycle the typed array
          icons.recycle();
          lvSlidingMenu.setOnItemClickListener(new SlideMenuClickListener());
  
          // Assign adapter to listview
          adapter = new SlidingMenuAdapter(getApplicationContext(), slidingMenuItems);
          lvSlidingMenu.setAdapter(adapter);
  
          // Enable action bar app icon and behaving it as toggle button
          getActionBar().setDisplayHomeAsUpEnabled(true);
          getActionBar().setHomeButtonEnabled(true);
          drawerToggle = new ActionBarDrawerToggle(this, drawerLayout, R.drawable.ic_drawer
                  // Navigation Drawer
                 , R.string.app_name,
                  //Navigation Drawer open - description for accessibility
                  R.string.app_name)
                  // Navigation Drawer close - description for accessibility
           {
              public void onDrawerClosed(View view) {
                  getActionBar().setTitle(appTitle);
                  invalidateOptionsMenu();
              }
  
              public void onDrawerOpened(View drawerView) {
                  getActionBar().setTitle(drawerTitle);
                  invalidateOptionsMenu();
              }
          }; drawerLayout.setDrawerListener(drawerToggle);
          if (savedInstanceState == null) {
              // On first time, show Home Fragment
              displayView(0);
          }
      }
  
      /**
       * Slide menu item click listener *
       */
      private class SlideMenuClickListener implements ListView.OnItemClickListener {
          @Override
          public void onItemClick(AdapterView&lt;?&gt; parent, View view, int position, long id) {
              // Display appropriate fragment for selected item
              displayView(position);
          }
      }
  
      @Override
      public boolean onCreateOptionsMenu(Menu menu) {
          getMenuInflater().inflate(R.menu.menu_main, menu);
          return true;
      }
  
      @Override
      public boolean onOptionsItemSelected(MenuItem item) {
          // Toggle Navigation Drawer on selecting action bar app icon/title
          if (drawerToggle.onOptionsItemSelected(item)) {
              return true;
          }
          // Handle action bar actions click
          switch (item.getItemId()) {
              case R.id.action_settings:
                  return true;
              default:
                  return super.onOptionsItemSelected(item);
          }
      } /* * * Called when invalidateOptionsMenu() is triggered */
  
      @Override
      public boolean onPrepareOptionsMenu(Menu menu) {
          // If Navigation Drawer is opened, hide the action items
          boolean drawerOpen = drawerLayout.isDrawerOpen(lvSlidingMenu);
          menu.findItem(R.id.action_settings).setVisible(!drawerOpen);
          return super.onPrepareOptionsMenu(menu);
      }
  
      /**
       * Display fragment view for selected Navigation Drawer list item *
       */
      private void displayView(int position) {
          Fragment fragment = null;
          switch (position) {
              case 0:
                  fragment = new HomeFragment();
                  break;
  
              default:
                  break;
          }
          if (fragment != null) {
              FragmentManager fragmentManager = getFragmentManager();
              fragmentManager.beginTransaction().replace(R.id.fragment_detail, fragment).commit();
  
              // Update selected item and title, then close the drawer
              lvSlidingMenu.setItemChecked(position, true);
              lvSlidingMenu.setSelection(position);
              setTitle(titles[position]);
              drawerLayout.closeDrawer(lvSlidingMenu);
          } else {
              // Log error
              Log.e("MainActivity", "Error in creating fragment");
          }
      }
  
      @Override
      public void setTitle(CharSequence title) {
          appTitle = title;
          getActionBar().setTitle(appTitle);
      }
  
      /**
       * When using the ActionBarDrawerToggle, you must call it during * onPostCreate() and onConfigurationChanged()...
       */
      @Override
      protected void onPostCreate(Bundle savedInstanceState) {
          super.onPostCreate(savedInstanceState);
          // Sync the toggle state after onRestoreInstanceState has occurred.
          drawerToggle.syncState();
      }
  
      @Override
      public void onConfigurationChanged(Configuration newConfig) {
          super.onConfigurationChanged(newConfig);
          // Pass any configuration change to the drawer toggls
          drawerToggle.onConfigurationChanged(newConfig);
      }
  }
  </code></pre>
  
  <p>This is my MainActivty.java</p>
  
  <pre><code>public class SlidingMenuAdapter extends BaseAdapter {
  
      private Context context;
      private ArrayList&lt;SlidingMenuItem&gt; items;
  
      public SlidingMenuAdapter(Context context, ArrayList&lt;SlidingMenuItem&gt; items) {
          this.context = context;
          this.items = items;
      }
  
      @Override
      public int getCount() {
          return items.size();
      }
  
      @Override
      public Object getItem(int index) {
          return items.get(index);
      }
  
      @Override
      public long getItemId(int index) {
          return index;
      }
  
      @Override
      public View getView(int index, View view, ViewGroup arg2) {
          if (view == null) {
              LayoutInflater mInflater = (LayoutInflater)
                      context.getSystemService(Activity.LAYOUT_INFLATER_SERVICE);
              view = mInflater.inflate(R.layout.iv_item_sliding_menu, null);
          }
  
          ImageView imgIcon = (ImageView) view.findViewById(R.id.img_sliding_menu_item);
          TextView txtTitle = (TextView) view.findViewById(R.id.tv_sliding_menu_item);
  
          SlidingMenuItem item = items.get(index);
  
          imgIcon.setImageResource(item.getIcon());
          txtTitle.setText(item.getTitle());
  
          return view;
      }
  
  } 
  </code></pre>
  
  <p>This is my adapter.java file</p>
  
  <pre><code>public class SlidingMenuItem {
      String title;
      int icon;
  
      public SlidingMenuItem(String title, int icon) {
          this.title = title;
          this.icon = icon;
      }
  
      public String getTitle() {
          return title;
      }
  
      public void setTitle(String title) {
          this.title = title;
      }
  
      public int getIcon() {
          return icon;
      }
  
      public void setIcon(int icon) {
          this.icon = icon;
      }
  
  }
  </code></pre>
  
  <p>And this is my menu item </p>
  
  <pre><code>&lt;resources&gt;
      &lt;string name="app_name" translatable="false"&gt;Fb slid&lt;/string&gt;
  
      &lt;string name="hello_world" translatable="false"&gt;Hello world!&lt;/string&gt;
      &lt;string name="action_settings" translatable="false"&gt;Settings&lt;/string&gt;
      &lt;string name="title_activity_main" translatable="false"&gt;MainActivity
      &lt;/string&gt;
  
  
          &lt;!-- Sliding Menu items --&gt;
   &lt;string-array name="nav_drawer_items"&gt;
      &lt;item &gt;Home&lt;/item&gt;
      &lt;item &gt;Notifications&lt;/item&gt;
      &lt;item &gt;Settings&lt;/item&gt;
      &lt;item &gt;About&lt;/item&gt;
  &lt;/string-array&gt;
  
          &lt;!-- Sliding Menu item icons --&gt;
          &lt;array name="nav_drawer_icons"&gt;
              &lt;item&gt;@drawable/home&lt;/item&gt;
              &lt;item&gt;@drawable/notifications&lt;/item&gt;
              &lt;item&gt;@drawable/settings&lt;/item&gt;
              &lt;item&gt;@drawable/about&lt;/item&gt;
          &lt;/array&gt;
  
      &lt;/resources&gt;
  </code></pre>
  
  <p>And this s my string.xml file</p>
  
  <p>Log cat :</p>
  
  <pre><code>10-03 11:02:06.217    6956-6956/com.example.first.fbslid E/AndroidRuntime﹕ FATAL EXCEPTION: main
      java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.first.fbslid/com.example.first.fbslid.MainActivity}: java.lang.ArrayIndexOutOfBoundsException: length=0; index=0
              at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2121)
              at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2146)
              at android.app.ActivityThread.access$700(ActivityThread.java:140)
              at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1238)
              at android.os.Handler.dispatchMessage(Handler.java:99)
              at android.os.Looper.loop(Looper.java:177)
              at android.app.ActivityThread.main(ActivityThread.java:4947)
              at java.lang.reflect.Method.invokeNative(Native Method)
              at java.lang.reflect.Method.invoke(Method.java:511)
  
              at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1038)
              at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:805)
              at dalvik.system.NativeStart.main(Native Method)
       Caused by: java.lang.ArrayIndexOutOfBoundsException: length=0; index=0
              at com.example.first.fbslid.MainActivity.onCreate(MainActivity.java:49)
              at android.app.Activity.performCreate(Activity.java:5207)
              at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1094)
              at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2085)
              at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2146)
              at android.app.ActivityThread.access$700(ActivityThread.java:140)
              at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1238)
              at android.os.Handler.dispatchMessage(Handler.java:99)
              at android.os.Looper.loop(Looper.java:177)
              at android.app.ActivityThread.main(ActivityThread.java:4947)
              at java.lang.reflect.Method.invokeNative(Native Method)
              at java.lang.reflect.Method.invoke(Method.java:511)
              at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1038)
             at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:805)
              at dalvik.system.NativeStart.main(Native Method).
  </code></pre>
  
  <p><strong>I don't know  where am getting error as am new to android  and am trying to create sliding menu like in facebook .  Can someone Please help me to resolve</strong></p>