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

  • Home
  • SEARCH
  • 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 6749045
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T12:38:33+00:00 2026-05-26T12:38:33+00:00

I have a list that will filter in input in an EditText field and

  • 0

I have a list that will filter in input in an EditText field and populate the ListView according to what they type.

For example, if the user types “al” it will populate names that have a first or last name beginning with “al.”

My problem is when the user backspaces the EditText field all the way back where no letters are typed, my program crashes. I’m not sure why my initial if statement isn’t getting used.

This is NOT an issue of the ListView being empty causing a crash, because if I type a name that isn’t in the list, the ListView will stay empty and not crash.

private void AlterAdapter() {
    partialNames.clear();

    if (searchName.getText().toString() == "")
        partialNames.add("There are no names that meet your criteria");
    else  {
            String seekString = searchName.getText().toString();
            String firstLetter = seekString.substring(0,1).toString().toUpperCase();
            Log.d("JAY", "The firstLetter is: " + firstLetter);

            if (!seekString.isEmpty() && seekString.length() == 1) {
                //firstLetter = seekString.toUpperCase();
                for (int i = 0; i < searchNames.size(); i++) {
                    if (searchNames.get(i).toString().contains(firstLetter)) {
                        partialNames.add(searchNames.get(i).toString());
                    }
                }
            }
            else if (!seekString.isEmpty() && seekString.length() > 1) {
                //searchCriteria = searchCriteria.concat(seekString);
                String searchWord = firstLetter.concat(seekString.substring(1,seekString.length()));
                Log.d("JAY", "The seekString is " + seekString);
                Log.d("JAY", "The searchWord is " + searchWord);
                for (int i = 0; i < searchNames.size(); i++) {
                    if (searchNames.get(i).toString().contains(searchWord)) {
                        partialNames.add(searchNames.get(i).toString());
                    }
                }
            }
    }
    adapter.notifyDataSetChanged();         
}

Here is the logcat:

D/AndroidRuntime( 1518): Shutting down VM

W/dalvikvm( 1518): threadid=1: thread exiting with uncaught exception
(group=0x40015560)

E/AndroidRuntime( 1518): FATAL EXCEPTION: main

E/AndroidRuntime( 1518): java.lang.StringIndexOutOfBoundsException

E/AndroidRuntime( 1518): at
java.lang.String.substring(String.java:1651)

E/AndroidRuntime( 1518): at
com.jaylefler.contacts.SearchContacts.AlterAdapter(SearchContacts.java:92)

E/AndroidRuntime( 1518): at
com.jaylefler.contacts.SearchContacts.access$0(SearchContacts.java:88)

E/AndroidRuntime( 1518): at
com.jaylefler.contacts.SearchContacts$1.onTextChanged(SearchContacts.java:73)

E/AndroidRuntime( 1518): at
android.widget.TextView.sendOnTextChanged(TextView.java:6295)

E/AndroidRuntime( 1518): at
android.widget.TextView.handleTextChanged(TextView.java:6336)

E/AndroidRuntime( 1518): at
android.widget.TextView$ChangeWatcher.onTextChanged(TextView.java:6485)

E/AndroidRuntime( 1518): at
android.text.SpannableStringBuilder.sendTextChange(SpannableStringBuilder.java:889)

E/AndroidRuntime( 1518): at
android.text.SpannableStringBuilder.change(SpannableStringBuilder.java:400)

E/AndroidRuntime( 1518): at
android.text.SpannableStringBuilder.change(SpannableStringBuilder.java:269)

E/AndroidRuntime( 1518): at
android.text.SpannableStringBuilder.replace(SpannableStringBuilder.java:432)

E/AndroidRuntime( 1518): at
android.text.SpannableStringBuilder.delete(SpannableStringBuilder.java:218)

E/AndroidRuntime( 1518): at
android.text.SpannableStringBuilder.delete(SpannableStringBuilder.java:28)

E/AndroidRuntime( 1518): at
android.text.method.BaseKeyListener.backspace(BaseKeyListener.java:60)

E/AndroidRuntime( 1518): at
android.text.method.BaseKeyListener.onKeyDown(BaseKeyListener.java:123)

E/AndroidRuntime( 1518): at
android.text.method.QwertyKeyListener.onKeyDown(QwertyKeyListener.java:327)

E/AndroidRuntime( 1518): at
android.text.method.TextKeyListener.onKeyDown(TextKeyListener.java:132)

E/AndroidRuntime( 1518): at
android.widget.TextView.doKeyDown(TextView.java:4433)

E/AndroidRuntime( 1518): at
android.widget.TextView.onKeyDown(TextView.java:4267)

E/AndroidRuntime( 1518): at
android.view.KeyEvent.dispatch(KeyEvent.java:1256)

E/AndroidRuntime( 1518): at
android.view.View.dispatchKeyEvent(View.java:3855)

E/AndroidRuntime( 1518): at
android.view.ViewGroup.dispatchKeyEvent(ViewGroup.java:789)

E/AndroidRuntime( 1518): at
android.view.ViewGroup.dispatchKeyEvent(ViewGroup.java:789)

E/AndroidRuntime( 1518): at
android.view.ViewGroup.dispatchKeyEvent(ViewGroup.java:789)

E/AndroidRuntime( 1518): at
android.view.ViewGroup.dispatchKeyEvent(ViewGroup.java:789)

E/AndroidRuntime( 1518): at
android.view.ViewGroup.dispatchKeyEvent(ViewGroup.java:789)

E/AndroidRuntime( 1518): at
android.view.ViewGroup.dispatchKeyEvent(ViewGroup.java:789)

E/AndroidRuntime( 1518): at
com.android.internal.policy.impl.PhoneWindow$DecorView.superDispatchKeyEvent(PhoneWindow.java:1687)

E/AndroidRuntime( 1518): at
com.android.internal.policy.impl.PhoneWindow.superDispatchKeyEvent(PhoneWindow.java:1120)

E/AndroidRuntime( 1518): at
android.app.Activity.dispatchKeyEvent(Activity.java:2073)

E/AndroidRuntime( 1518): at
com.android.internal.policy.impl.PhoneWindow$DecorView.dispatchKeyEvent(PhoneWindow.java:1663)

E/AndroidRuntime( 1518): at
android.view.ViewRoot.deliverKeyEventToViewHierarchy(ViewRoot.java:2560)

E/AndroidRuntime( 1518): at
android.view.ViewRoot.handleFinishedEvent(ViewRoot.java:2535)

E/AndroidRuntime( 1518): at
android.view.ViewRoot.handleMessage(ViewRoot.java:1867)

E/AndroidRuntime( 1518): at
android.os.Handler.dispatchMessage(Handler.java:99)

E/AndroidRuntime( 1518): at android.os.Looper.loop(Looper.java:123)

E/AndroidRuntime( 1518): at
android.app.ActivityThread.main(ActivityThread.java:3683)

E/AndroidRuntime( 1518): at
java.lang.reflect.Method.invokeNative(Native Method)

E/AndroidRuntime( 1518): at
java.lang.reflect.Method.invoke(Method.java:507)

E/AndroidRuntime( 1518): at
com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:839)

E/AndroidRuntime( 1518): at
com.android.internal.os.ZygoteInit.main(ZygoteInit.java:597)

E/AndroidRuntime( 1518): at dalvik.system.NativeStart.main(Native
Method)

W/ActivityManager( 74): Force finishing activity
com.jaylefler.contacts/.SearchContacts

W/ActivityManager( 74): Activity pause timeout for
HistoryRecord{4086e540 com.jaylefler.contacts/.SearchContacts}

I/Process ( 1518): Sending signal. PID: 1518 SIG: 9

I/ActivityManager( 74): Process com.jaylefler.contacts (pid 1518)
has died.

E/InputDispatcher( 74): channel ‘409a83e8
com.jaylefler.contacts/com.jaylefler.contacts.ContactProjectActivity
(server)’ ~ Consumer closed input channel or an error occurred.
events=0x8

E/InputDispatcher( 74): channel ‘409a83e8
com.jaylefler.contacts/com.jaylefler.contacts.ContactProjectActivity
(server)’ ~ Channel is unrecoverably broken and will be disposed!

I/WindowManager( 74): WIN DEATH: Window{4086ff40
com.jaylefler.contacts/com.jaylefler.contacts.SearchContacts
paused=false}

I/WindowManager( 74): WIN DEATH: Window{409a83e8
com.jaylefler.contacts/com.jaylefler.contacts.ContactProjectActivity
paused=false}

E/InputDispatcher( 74): Received spurious receive callback for
unknown input channel. fd=150, events=0x8

W/InputManagerService( 74): Got RemoteException sending
setActive(false) notification to pid 1518 uid 10030

  • 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-05-26T12:38:33+00:00Added an answer on May 26, 2026 at 12:38 pm

    I think the prob;em is that you use ‘==’ for comparing searchName text with empty string. Such a comparison will always produce false. Use equals method instead or compare text length with 0.

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

Sidebar

Related Questions

I'd like to implement a ListView that will have a list of SelectedItems as
I'm writing a filter that will pick out items. I have a list of
I have a list that the user can filter in several ways. two of
I have a list of Foos that I would like to filter according to
I am creating an application that will have a list of items that can
I have a dynamic list of items that will be used to POST information
So let's assume I have a class named ABC that will have a list
I have an event handler that will remove an element from a list of
I want to have a function that will return the reverse of a list
I have a SQL Server 2000 database that will not display the column list

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.