Problem in my search engine code

Asked

Viewed 49 times

0

As I can not use searchview I decided to use an edittext and a logica q found on a forum, but I go through difficulties have some idea?

imagem do código com o erro

Mainactivity.class

public void CarregarEncontrados()
{

   int textlength = et.getText().length();

   //Limpa o array com os estados encontrados
   //para poder efetuar nova busca
   lstEstados_Encontrados.clear();

   for (int i = 0; i < item.size(); i++)
   {
       if (textlength <= item.get(i).getResId())
       {
           //Verifica se existe algum item no array original
           //caso encontre é adicionado no array de encontrados
           if(et.getText().toString().equalsIgnoreCase((String)item[i].subSequence(0, textlength)))
           {
               lstEstados_Encontrados.add(item.get(i));
           }
       }
   }
}

2 answers

0

Try to replace with this code:

Example

public void CarregarEncontrados()
{

   int textlength = et.getText().length();

   //Limpa o array com os estados encontrados
   //para poder efetuar nova busca
   lstEstados_Encontrados.clear();

   for (int i = 0; i < item.size(); i++)
   {
       if (textlength <= item.get(i).getResId())
       {
           //Verifica se existe algum item no array original
           //caso encontre é adicionado no array de encontrados
           if(et.getText().toString().equalsIgnoreCase(item.get(i).subSequence(0, textlength)))
           {
               lstEstados_Encontrados.add(item.get(i));
           }
       }
   }
}

0

What I understand from your question is that you are in trouble on line 129 of the picture.

If this is really the case, I believe the problem is that you try to access an element of ArrayList with [], but the correct is with the get(int index), that is, similar to what you do on line 125.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.