title: Arraylist that sometimes contain data, and sometimes not
body: <p>A newbie for here. </p>
  
  <p>I'm working in an app with Android and a strange thing happens to me with a While loop. I make a series of requests to the database with volley library and it returns the data well. No problem.</p>
  
  <p>The problem, i think, is in the last function DameColorPlato(), because sometimes the code accesses the while loop and it passes through it well, but sometimes it does not, and it returns the default value of the CC variable (#000000) and it does not show me well the colors of the text.</p>
  
  <p>This is my code (In summary):</p>
  
  <pre><code> protected void onCreate(Bundle savedInstanceState) {
           super.onCreate(savedInstanceState);
           setContentView(R.layout.activity_menu);
  
       Bundle datos = getIntent().getExtras();
       id_usuario = datos.getString("id_usuario");
       idCentro = datos.getString("id_centro");
       fecha_actual = datos.getString("fechaActual");
       fecha_actual_SQL = datos.getString("fechaActualSQL");
  
  
           plato1 = (TextView)findViewById(R.id.textView4);
           plato2 = (TextView)findViewById(R.id.textView3);
  
  
  
           ObtPlatos_volley(idCentro, fecha_actual_SQL);
  
           ObtColores_volley();
  
  
       public void ObtPlatos_volley(final String id_centro, final String fecha_actual_SQL){
  
  
           String url = "http://neton.es/WS_neton/menu_dia.php?id_centro="+id_centro+"&amp;fecha_actual_SQL="+fecha_actual_SQL;
  
           StringRequest eventfulRequest = new StringRequest(Request.Method.GET, url,
                   new Response.Listener&lt;String&gt;() {
                       @Override
                       public void onResponse(String response) {
                           try {
  
                               JSONArray jsonArray = new JSONArray(response);
  
                               for (int i=0; i&lt;jsonArray.length(); i++) {
  
  
                                   platouno = jsonArray.getJSONObject(i).getString("plato1");
                                   platodos = jsonArray.getJSONObject(i).getString("plato2");
  
  
  
                                   platounoColor = jsonArray.getJSONObject(i).getInt("tipo1");
                                   platodosColor = jsonArray.getJSONObject(i).getInt("tipo2");
  
  
                               }
  
  
                                   plato1.setText(platouno);
  
                                   String co1 = DameColorPlato(CodTipoPlato, ColorLetra, platounoColor);
  
                                   plato1.setTextColor(Color.parseColor(co1));
  
  
  
                                   plato2.setText(platodos);
  
                                   String co2 = DameColorPlato(CodTipoPlato, ColorLetra, platodosColor);
  
                                   plato2.setTextColor(Color.parseColor(co2));
  
  
  
                           } catch (Exception e) {
                               e.printStackTrace();
  
                           }
                       }
                   },
                   new Response.ErrorListener() {
                       @Override
                       public void onErrorResponse(VolleyError error) {
                           Log.e("Error: ", error.toString());
                       }
                   });
  
           VolleySingleton.getInstance(this)
                   .addToRequestQueue(eventfulRequest);
       }
  
  
  
       public void ObtColores_volley(){
  
           String url = "http://neton.es/WS_neton/color_platos.php";
  
           StringRequest eventfulRequest = new StringRequest(Request.Method.GET, url,
                   new Response.Listener&lt;String&gt;() {
                       @Override
                       public void onResponse(String response) {
                           try {
  
                               int cod_color_letra;
                               String color_letra;
  
  
                               JSONArray jsonArray = new JSONArray(response);
  
                               for (int i=0; i&lt;jsonArray.length(); i++){
  
                                   cod_color_letra = jsonArray.getJSONObject(i).getInt("cod_tipoplato");
                                   color_letra = jsonArray.getJSONObject(i).getString("color");
  
                                   CodTipoPlato.add(cod_color_letra);
                                   ColorLetra.add(color_letra);
                               }
  
                           } catch (Exception e) {
                               e.printStackTrace();
  
                           }
                       }
                   },
                   new Response.ErrorListener() {
                       @Override
                       public void onErrorResponse(VolleyError error) {
                           Log.e("Error: ", error.toString());
                       }
                   });
  
           VolleySingleton.getInstance(this)
                   .addToRequestQueue(eventfulRequest);
       }
  
  
  
       public String DameColorPlato(ArrayList&lt;Integer&gt; CodColorL, ArrayList&lt;String&gt; ColorL, int tipoplato){
  
           String CC="#000000";
           int i=0;
           boolean encontrado=false;
  
  
       while (i &lt; CodColorL.size() &amp;&amp; !encontrado) {
  
           if (tipoplato == CodColorL.get(i)) {
  
               CC = ColorL.get(i);
  
               encontrado = true;
  
           }else {
               i++;
           }
  
       }
           return CC;
       } 
  }
  </code></pre>
  
  <p>With a Toast I have found that ArrayList CodColorL and ArrayList ColorL variables sometimes come with values, and sometimes they come empty. But i cannot found the error.</p>
  
  <p>Thanks in advance!</p>
  
  <p>(sorry for my bad English)</p>