Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8530477
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T09:15:19+00:00 2026-06-11T09:15:19+00:00

advancing on my project, I am fighting with a problem I cannot solve.. Wanting

  • 0

advancing on my project, I am fighting with a problem I cannot solve..

Wanting to run a search function on a ListView so I used an EditText.

My problem: my method works well when I get two characters in the EditText and shows only items containing “Name” that I passed on it, but when I get a third character,then application crashes..

here is my log:

09-14 16:49:05.647: E/AndroidRuntime(20020): FATAL EXCEPTION: main
09-14 16:49:05.647: E/AndroidRuntime(20020): java.lang.StringIndexOutOfBoundsException: length=2; regionStart=0; regionLength=3
09-14 16:49:05.647: E/AndroidRuntime(20020):    at java.lang.String.startEndAndLength(String.java:593)
09-14 16:49:05.647: E/AndroidRuntime(20020):    at java.lang.String.substring(String.java:1474)
09-14 16:49:05.647: E/AndroidRuntime(20020):    at java.lang.String.subSequence(String.java:1861)
09-14 16:49:05.647: E/AndroidRuntime(20020):    at com.android.bordeaux.code.MyListActivity$3.onTextChanged(MyListActivity.java:126)
09-14 16:49:05.647: E/AndroidRuntime(20020):    at android.widget.TextView.sendOnTextChanged(TextView.java:8315)
09-14 16:49:05.647: E/AndroidRuntime(20020):    at android.widget.TextView.handleTextChanged(TextView.java:8362)
09-14 16:49:05.647: E/AndroidRuntime(20020):    at android.widget.TextView$ChangeWatcher.onTextChanged(TextView.java:8725)
09-14 16:49:05.647: E/AndroidRuntime(20020):    at android.text.SpannableStringBuilder.sendTextChange(SpannableStringBuilder.java:892)
09-14 16:49:05.647: E/AndroidRuntime(20020):    at android.text.SpannableStringBuilder.change(SpannableStringBuilder.java:352)
09-14 16:49:05.647: E/AndroidRuntime(20020):    at android.text.SpannableStringBuilder.change(SpannableStringBuilder.java:266)
09-14 16:49:05.647: E/AndroidRuntime(20020):    at android.text.SpannableStringBuilder.replace(SpannableStringBuilder.java:443)
09-14 16:49:05.647: E/AndroidRuntime(20020):    at android.text.SpannableStringBuilder.replace(SpannableStringBuilder.java:420)
09-14 16:49:05.647: E/AndroidRuntime(20020):    at android.text.SpannableStringBuilder.replace(SpannableStringBuilder.java:29)
09-14 16:49:05.647: E/AndroidRuntime(20020):    at android.view.inputmethod.BaseInputConnection.replaceText(BaseInputConnection.java:667)
09-14 16:49:05.647: E/AndroidRuntime(20020):    at android.view.inputmethod.BaseInputConnection.commitText(BaseInputConnection.java:188)
09-14 16:49:05.647: E/AndroidRuntime(20020):    at com.android.internal.widget.EditableInputConnection.commitText(EditableInputConnection.java:149)
09-14 16:49:05.647: E/AndroidRuntime(20020):    at com.android.internal.view.IInputConnectionWrapper.executeMessage(IInputConnectionWrapper.java:279)
09-14 16:49:05.647: E/AndroidRuntime(20020):    at com.android.internal.view.IInputConnectionWrapper$MyHandler.handleMessage(IInputConnectionWrapper.java:77)
09-14 16:49:05.647: E/AndroidRuntime(20020):    at android.os.Handler.dispatchMessage(Handler.java:99)
09-14 16:49:05.647: E/AndroidRuntime(20020):    at android.os.Looper.loop(Looper.java:137)
09-14 16:49:05.647: E/AndroidRuntime(20020):    at android.app.ActivityThread.main(ActivityThread.java:4517)
09-14 16:49:05.647: E/AndroidRuntime(20020):    at java.lang.reflect.Method.invokeNative(Native Method)
09-14 16:49:05.647: E/AndroidRuntime(20020):    at java.lang.reflect.Method.invoke(Method.java:511)
09-14 16:49:05.647: E/AndroidRuntime(20020):    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:993)
09-14 16:49:05.647: E/AndroidRuntime(20020):    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:760)
09-14 16:49:05.647: E/AndroidRuntime(20020):    at dalvik.system.NativeStart.main(Native Method)

And this is my code:

inputSearch = (EditText) findViewById(R.id.inputSearch);

inputSearch.addTextChangedListener(new TextWatcher() {
                  public void onTextChanged(CharSequence s, int start, int before, int count)
                  {
                      textlength = inputSearch.getText().length();
                      String query = inputSearch.getText().toString();

                      arr_sort.clear();
                      for(int i=0;i < currentArray.size();i++)
                      {
                          if(textlength <= currentArray.get(i).getName().length())
                          {
                              String[] wordArray = currentArray.get(i).getName().split(" ");
                              for (int j = 0; j < wordArray.length; j++)
                              {
                                  if(query.equalsIgnoreCase((String) wordArray[j].subSequence(0, textlength)))
                                  {
                                      arr_sort.add(currentArray.get(i));
                                      break;
                                  }
                              }
                          }
                      }
                    list_adapter = new announcersListAdapter(MyListActivity.this, R.layout.tab_list_item, arr_sort);
                    setListAdapter(list_adapter);

                  }

                    public void beforeTextChanged(CharSequence arg0, int arg1, int arg2,
                            int arg3) {
                    }

                    public void afterTextChanged(Editable s) {
                    }
                });

Thanks to help me guys 🙂

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-11T09:15:20+00:00Added an answer on June 11, 2026 at 9:15 am

    Does it work any better if you change this line;

    if(query.equalsIgnoreCase((String) wordArray[j].subSequence(0, textlength)))
    

    with

    if(query.equalsIgnoreCase(wordArray[j].substring(0,
                              Math.min(wordArray[j].length(), textlength))))
    

    ?

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a function that is advancing scrolling images on a webpage. It can
Following code shows the problem: Advancing a full year from the first day of
I have a method that gets rows from my database. It looks like this:
I wrote a very simple C function to illustrate what I would like to
How do I stop a NSIS Custom Page from advancing to the next page?
I'm using the wonderful reveal.js library to create a HTML slideshow. My only problem
In my current project, I'm producing weekly releases. I've been using the technique described
As I experienced about non-SQL databases, one of biggest problem was schema change. Adding
I'm new to programing and was given a task of making a function that
I would like a code sample for a function that takes a tDateTime and

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.