unable to retrieve all the values of vector element
<p>I am trying to fetch the values of vector but 1 time its giving me exactly the right value while the other time it doesn't return me the value. can anyone fix this bug
In add CreateTable it returns me the exact value while in <code>AddFavDialog()</code> it shows the value of <code>array1[3]</code>, rest values are returned as empty string.<img src="http://i.stack.imgur.com/vKjwm.png" alt="enter image description here">
Output of CreateTable</p>

<pre><code>package people.finder;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.List;
import java.util.Vector;

import org.apache.http.HttpEntity;
import org.apache.http.HttpResponse;
import org.apache.http.NameValuePair;
import org.apache.http.client.ClientProtocolException;
import org.apache.http.client.HttpClient;
import org.apache.http.client.entity.UrlEncodedFormEntity;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.impl.client.DefaultHttpClient;
import org.apache.http.message.BasicNameValuePair;

import android.app.Activity;
import android.app.AlertDialog;
import android.content.ActivityNotFoundException;
import android.content.DialogInterface;
import android.content.Intent;
import android.graphics.Color;
import android.net.Uri;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.view.ViewGroup;
import android.view.View.OnClickListener;
import android.view.ViewGroup.LayoutParams;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TableLayout;
import android.widget.TableRow;
import android.widget.TextView;
import android.widget.Toast;


public class FindPeople extends Activity implements OnClickListener{
DataSource datasource=new DataSource(this);
Button findButton,backButton;
TableLayout tableLayout; 
ArrayList&lt;String&gt; listArray=new ArrayList&lt;String&gt;();
EditText txtsearch;
String array1[]=null;
String array2[]=null;
Vector&lt;String[]&gt; vect=new Vector&lt;String[]&gt;();
Vector&lt;String[]&gt; v1=new Vector&lt;String[]&gt;();
String number[]=null;      
TableRow row,row1;
    protected void onCreate (Bundle savedInstanceState) 
    {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.finddetails);
        findViews();
        setListeners();
        createTable();
    }
    public void findViews ()
    {
        txtsearch=(EditText)findViewById(R.id.txtsearch);
        findButton = (Button) findViewById (R.id.btnfind);
        backButton = (Button) findViewById (R.id.btnback);

    }
    public void setListeners () 
    {
        findButton.setOnClickListener(this);
        backButton.setOnClickListener(this);
    }
    @Override
    public void onClick(View v)
    {
        // TODO Auto-generated method stub
        switch (v.getId()) 
        {
        case R.id.btnfind:
            if(!txtsearch.getText().toString().trim().equals(""))
                search_details();
            break;
        case R.id.btnback:
            finish();
            break;

        }

}   
     public void removeTableRows()
     {
        int count = tableLayout.getChildCount();
         for (int i =1; i &lt; count; i++)
         {
             View child = tableLayout.getChildAt(i);
             if (child instanceof TableRow) ((ViewGroup) child).removeAllViews();
         }
    }
    private void call(String number) {
        try {
            Intent callIntent = new Intent(Intent.ACTION_CALL);
            callIntent.setData(Uri.parse("tel:"+number));
            startActivity(callIntent);
        } catch (ActivityNotFoundException activityException) {
            Log.e("dialing-example", "Call failed", activityException);
        }
    }
    private void sendSMS(String phoneNumber)
    {
        Intent intent = new Intent( Intent.ACTION_VIEW, Uri.parse( "sms:" + phoneNumber ) ); 
        intent.putExtra( "sms_body", "" );
        startActivity( intent );

    } 
    private void email(String receipient)
    {
        final Intent emailIntent = new Intent(android.content.Intent.ACTION_SEND);
        emailIntent.setType("plain/text");
        emailIntent.putExtra(android.content.Intent.EXTRA_EMAIL, new String[]{ receipient});
        emailIntent.putExtra(android.content.Intent.EXTRA_SUBJECT, "");
        emailIntent.putExtra(android.content.Intent.EXTRA_TEXT,"");
        FindPeople.this.startActivity(Intent.createChooser(emailIntent, "Send mail..."));

    }

public void search_details()
    {
        try 
        {
            array1=null;
            number=null;
            vect.clear();
            v1.clear();
            HttpClient httpclient = new DefaultHttpClient();
            HttpPost httppost = new HttpPost("http://192.168.0.133/peoplefinder/search.php");
            List&lt;NameValuePair&gt; nameValuePairs = new ArrayList&lt;NameValuePair&gt;(1);       
            nameValuePairs.add(new BasicNameValuePair("search",txtsearch.getText().toString().trim()));
            httppost.setEntity(new UrlEncodedFormEntity(nameValuePairs));
            // Execute HTTP Post Request
            HttpResponse response = httpclient.execute(httppost);
            HttpEntity entity = response.getEntity();
            InputStream instream = entity.getContent();
            String res = convertStreamToString(instream);           
            if(res.trim().equals("Failed"))
            {   
            }
            else
            {
                removeTableRows();
                res=res.substring(1,res.length()-1);
                while(res.length()&gt;3)
                {
                    int index=res.indexOf("[");
                    int index1=res.indexOf("]");
                    String demo=res.substring(index+2, index1-1);
                    array1=demo.split(","); 
                    vect.add(array1);
                    v1.add(array1);
                    res=res.substring(index1+1);
                 }

                createTableLayout();
            } 
    } 
    catch (ClientProtocolException e) 
    {
        // TODO Auto-generated catch block
    }
    catch (IOException e) 
    {
        // TODO Auto-generated catch block
    }
        catch(Exception e)
        {
            Log.e("log_tag", "Error converting result "+e.toString());
        }
    }
public void SelectDialog (final String number1) 
{
    AlertDialog.Builder mainBuilder = new AlertDialog.Builder(this);
    mainBuilder.setMessage("Select Call/Sms")
           .setCancelable(false)
           .setPositiveButton("Call", new DialogInterface.OnClickListener() 
           {
               public void onClick(DialogInterface dialog, int id) 
               {
                call(number1);   
               }
           })
            .setNeutralButton("Sms", new DialogInterface.OnClickListener() {
               public void onClick(DialogInterface dialog, int id) 
               {
                 sendSMS(number1);                     
               }
           })
           .setNegativeButton("Cancel", new DialogInterface.OnClickListener() {
               public void onClick(DialogInterface dialog, int id) 
               {

               }
           });

    AlertDialog mainAlert = mainBuilder.create();
    mainAlert.show();
}
public void SelectEmailDialog (final String email)
{
    AlertDialog.Builder mainBuilder = new AlertDialog.Builder(this);
    mainBuilder.setMessage("Send Email")
           .setCancelable(false)
           .setPositiveButton("Email", new DialogInterface.OnClickListener() 
           {
               public void onClick(DialogInterface dialog, int id) 
               {
                email(email);   
               }
           })
          .setNegativeButton("Cancel", new DialogInterface.OnClickListener() {
               public void onClick(DialogInterface dialog, int id) 
               {

               }
           });

    AlertDialog mainAlert = mainBuilder.create();
    mainAlert.show();
}
public void createTable()
{
    tableLayout=(TableLayout)findViewById(R.id.pepole_TL);
    TextView nameTV, deptTV, officeTV, phonesTV, emailTV;
    row = new TableRow (this);
    nameTV = new TextView(this);
    deptTV = new TextView(this);
    officeTV = new TextView(this);
    phonesTV = new TextView(this);
    emailTV = new TextView(this);

    nameTV.setText("Name");
    deptTV.setText("Dept");
    officeTV.setText("Office");
    phonesTV.setText("Phones");
    emailTV.setText("E-mail");

    nameTV.setPadding(10, 10, 10, 10);
    deptTV.setPadding(10, 10, 10, 10);
    officeTV.setPadding(10, 10, 10, 10);
    phonesTV.setPadding(10, 10, 10, 10);
    emailTV.setPadding(10, 10, 10, 10);

    nameTV.setTextColor(R.color.black);
    deptTV.setTextColor(R.color.black);
    officeTV.setTextColor(R.color.black);
    phonesTV.setTextColor(R.color.black);
    emailTV.setTextColor(R.color.black);

    row.addView(nameTV);
    row.addView(deptTV);
    row.addView(officeTV);
    row.addView(phonesTV);
    row.addView(emailTV);
    row.setBackgroundColor(R.color.white);
    tableLayout.addView(row, new TableLayout.LayoutParams(LayoutParams.MATCH_PARENT,
            LayoutParams.WRAP_CONTENT));

}
public void createTableLayout()
{
    for(int i=0; i&lt;vect.size(); i++) 
    {
        array1=(String[])vect.get(i);
        number=array1[3].split("-");
        Log.d("number length",""+number.length);
        for(int k=0;k&lt;number.length;k++)
        {
            row = new TableRow (this);
            final TextView name_tv = new TextView(this);
            final TextView dept_tv = new TextView(this);
            final TextView office_tv = new TextView(this);
            final TextView phones_tv = new TextView(this);
            final TextView email_tv = new TextView(this);
            name_tv.setText(array1[0].trim());
            dept_tv.setText(array1[1].trim());
            office_tv.setText(array1[2].trim());
            phones_tv.setText(number[k].trim());
            email_tv.setText(array1[4].trim());
            phones_tv.setOnClickListener(new OnClickListener() {
            @Override
            public void onClick(View v)
                {
                    String phn=  phones_tv.getText().toString();
                    phn=phn.trim().substring(3);
                    Log.d ("Phones_tv", phn);
                    SelectDialog(phn);
                }
            });
            email_tv.setOnClickListener(new OnClickListener() {

            @Override
            public void onClick(View v) {
                // TODO Auto-generated method stub
                Log.d("email_tv", email_tv.getText().toString());
                if(!email_tv.getText().toString().trim().equals(""))
                SelectEmailDialog (email_tv.getText().toString().trim());
            }
            });
            name_tv.setPadding(10, 10, 10, 10);
            dept_tv.setPadding(10, 10, 10, 10);
            office_tv.setPadding(10, 10, 10, 10);
            phones_tv.setPadding(10, 10, 10, 10);
            email_tv.setPadding(10, 10, 10, 10);
            name_tv.setTextColor(R.color.black);
            dept_tv.setTextColor(R.color.black);
            office_tv.setTextColor(R.color.black);
            phones_tv.setTextColor(R.color.black);
            email_tv.setTextColor(R.color.black);
            row.addView(name_tv);
            row.addView(dept_tv);
            row.addView(office_tv);
            row.addView(phones_tv);
            row.addView(email_tv);  
            TableLayout.LayoutParams params = new TableLayout.LayoutParams(LayoutParams.MATCH_PARENT, 
                LayoutParams.WRAP_CONTENT);
            tableLayout.addView(row, params);
            if(!array1[0].equals(""))
            {
                row.setOnLongClickListener(new View.OnLongClickListener()
                {
                    @Override
                    public boolean onLongClick(View arg0) 
                    {
                        row1=(TableRow)arg0;
                        arg0.setBackgroundColor(Color.LTGRAY);
                        AddFavDialog();
                        return false;
                    }
                });
            }
            array1[0]="";
            array1[1]="";
            array1[2]="";
            array1[4]="";
        }
    }
}
public void AddFavDialog ()
{
    AlertDialog.Builder mainBuilder = new AlertDialog.Builder(this);
    mainBuilder.setMessage("Do You want to add this to favourites")
           .setCancelable(false)
           .setPositiveButton("Yes", new DialogInterface.OnClickListener() 
           {
               public void onClick(DialogInterface dialog, int id) 
               {
                   TextView tvname =   (TextView)(((TableRow)row1)).getChildAt(0);
                   String name1=tvname.getText().toString();
                   Log.d("vector size",""+v1.size());
                   Log.d("name1",name1);
                   number=null;
                   for(int i=0; i&lt;v1.size(); i++) 
                   {
                       array1=null;
                       number=null;
                       array2=(String[])v1.get(i);
                       number=array2[3].split("-");
                       String str=array2[3].toString().trim();
                       String str1=array2[0].toString().trim();
                       Log.d("array","jhj"+str);
                       Log.d("array","fsd"+str1);
//                       System.out.println("hee"+number.length);
//                       for(int k=0;k&lt;number.length;k++)
//                       {
//                                  
//                       System.out.println(array1[k]);
//                       }
                   }


                }
           })
          .setNegativeButton("No", new DialogInterface.OnClickListener() {
               public void onClick(DialogInterface dialog, int id) 
               {

               }
           });

    AlertDialog mainAlert = mainBuilder.create();
    mainAlert.show();
}
public static String convertStreamToString(InputStream is)
 {
    BufferedReader reader = new BufferedReader(new InputStreamReader(is));
    StringBuilder sb = new StringBuilder();
    String line = null;
    try 
    {
        while ((line = reader.readLine()) != null)
        {
             sb.append(line + "\n");
        }
    }
    catch (IOException e) 
    {
        e.printStackTrace();
    } 
    finally 
    {
        try 
        {
           is.close();
        } 
        catch (IOException e) 
        {
            e.printStackTrace();
        }
    }
   return sb.toString();
 }
}
</code></pre>
