title: creating list through base adapter but,throwing array index out of bound exception
body: <p>I want to show items in a <code>ListView</code> using <code>BaseAdapter</code>. I got the items in an array using a cursor and a content provider class. I saved the data in an array and want to use the <code>BaseAdapter</code> for displaying it in a <code>ListView</code> but it is throwing an <code>ArrayIndexOutOfBoundException</code>. I am totally confused about this problem.</p>
  
  <pre><code>public class CustomProviderDemo extends ListActivity {
  private EditText mContactNameEditText;
  private TextView mContactsText;
  private Button mContactSaveButton;
  static String id = null;
  static String userName = null;
  static String[] usr;
  static String gallerynames;
  @Override
  protected void onCreate(Bundle savedInstanceState) {
      super.onCreate(savedInstanceState);
      setContentView(R.layout.custom_provider);
  
      mContactNameEditText = (EditText) findViewById(R.id.contactNameEditText);
      mContactSaveButton = (Button) findViewById(R.id.contactSaveButton);
  
  
      mContactSaveButton.setOnClickListener(new View.OnClickListener() {
          public void onClick(View v) {
              String name = mContactNameEditText.getText().toString();
              insertRecord(name);
  
  
          }
      });
  
  
          displayRecords();
           setListAdapter(new MyAdapter(this));
  }
     public void insertRecord(String userName) {
          ContentValues values = new ContentValues();
          values.put(MyUsers.User.USER_NAME, userName);
          getContentResolver().insert(MyUsers.User.CONTENT_URI, values);
      }
  
   private void displayRecords() {
          // An array specifying which columns to return.
          String columns[] = new String[] { MyUsers.User._ID,
                  MyUsers.User.USER_NAME };
          Uri myUri = MyUsers.User.CONTENT_URI;
          Cursor cur = managedQuery(myUri, columns, // Which columns to return
                  null, // WHERE clause; which rows to return(all rows)
                  null, // WHERE clause selection arguments (none)
                  null // Order-by clause (ascending by name)
          );
          if (cur.moveToFirst()) {
  
              do {
                  id = cur.getString(cur.getColumnIndex(MyUsers.User._ID));
                  userName = cur.getString(cur
                          .getColumnIndex(MyUsers.User.USER_NAME));
                  Log.i("fgvd",id);
  
                  usr = new String[id.length()];
                   for(int i=0;i&lt;id.length();i++){
  
  
                       usr[i] =userName; 
                       Log.i("fgvd",usr[i]);
               }
  
                  //Toast.makeText(this, id + " " + userName, Toast.LENGTH_LONG).show();
              }
              while (cur.moveToNext());
  
          }
  
      }
  class MyAdapter extends BaseAdapter implements OnClickListener
   {
  
                  private LayoutInflater inflater;
  
                  public MyAdapter(Context ctx) {
                      super();
                      this.inflater = (LayoutInflater) ctx.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
                  }        
  
                  @Override
                  public int getCount() {
                      return CustomProviderDemo.userName.length();
                  }
  
                  /* Not implemented but not really needed */
                  @Override
                  public Object getItem(int position) {
                      return null;
                  }
  
                  /* Not implemented but not really needed */
                  @Override
                  public long getItemId(int position) { 
                      return 0;
                  }
  
  
                  @Override
                  public View getView(int position, View ConvertView, ViewGroup parent) 
                  {
                      View v = inflater.inflate(R.layout.listitem_layout, parent, false);
  
                      //throwing array index out of bund exceotion here
                      gallerynames = CustomProviderDemo.usr[position];
                      TextView tv = (TextView) v.findViewById(R.id.barrio);
                      tv.setText("gallerynames");
  
  
  
                      return v;
                  }
  
                 @Override
                  public void onClick(DialogInterface dialog, int which) {
                      // TODO Auto-generated method stub
  
                  }
  
   }
  </code></pre>