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 6977141
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T17:35:15+00:00 2026-05-27T17:35:15+00:00

Hi I’m trying to make an app in which there’s a search box, I’ve

  • 0

Hi I’m trying to make an app in which there’s a search box, I’ve written some code but, when I try to type the first letter in the AutoCompleteTextView, it gives me an error (java.lang.NullPointerException) without any kind of cause about what caused it.

My mains.xml:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
 android:orientation="vertical"
 android:layout_width="fill_parent"
 android:layout_height="fill_parent">
<AutoCompleteTextView
 android:id="@+id/acTV"
 android:layout_width="match_parent"
 android:layout_height="wrap_content"
 android:hint="Scrivi">
<requestFocus />
</AutoCompleteTextView>
<ListView android:id="@+id/list" 
 android:layout_height="wrap_content" 
 android:layout_width="match_parent"
 android:fadingEdge="none" 
 android:fastScrollEnabled="true">
</ListView>
</LinearLayout>

My listitem_row.xml:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
 xmlns:android="http://schemas.android.com/apk/res/android"
 android:orientation="vertical"
 android:layout_width="match_parent"
 android:layout_height="match_parent">
<TextView
 android:id="@+id/textView1"
 android:text="TextView"
 android:layout_height="wrap_content"
 android:textAppearance="?android:attr/textAppearanceLarge" 
 android:layout_width="fill_parent">
</TextView>
<TextView
 android:text="TextView"
 android:id="@+id/textView2"
 android:layout_width="fill_parent"
 android:layout_height="wrap_content">
</TextView>
</LinearLayout>

My code:

public class Search extends Activity {
    AutoCompleteTextView acTV;
    ListView lview;

    String[] first = {"One", "Two", "Three", "Four", "Five", "Six", "Seven", "Eight", "Nine", "Ten"};

    String[] second = {"Uno", "Due", "Tre", "Quattro", "Cinque", "Sei", "Sette", "Otto", "Nove", "Dieci"};
    int textlength = 0;
    ArrayList<String> first_sort = new ArrayList<String>();
    ArrayList<String> second_sort = new ArrayList<String>();

    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.mains);

        acTV = (AutoCompleteTextView) findViewById(R.id.acTV);
        lview = (ListView) findViewById(R.id.list);
        lview.setAdapter(new MyCustomAdapter(first, second));

        lview.setClickable(true);
        lview.setOnItemClickListener(new OnItemClickListener() {
            public void onItemClick(AdapterView<?> adapter, View view, int position, long id) {

                Intent intent = new Intent(Search.this, Details.class);
                startActivity(intent);
            }

            {
            }
        });

        lview.setTextFilterEnabled(true);
        acTV.addTextChangedListener(new TextWatcher() {

            public void afterTextChanged(Editable s) {
            }

            public void beforeTextChanged(CharSequence s, int start, int count, int after) {
            }

            public void onTextChanged(CharSequence s, int start,
                                      int before, int count) {

                textlength = acTV.getText().length();
                first_sort.clear();
                second_sort.clear();
                for (int i = 0; i < first.length; i++) {
                    if (textlength <= first[i].length()) {
                        if (acTV.getText().toString().equalsIgnoreCase((String) first[i].subSequence(0, textlength))) {
                            first_sort.add(first[i]);
                            second_sort.add(first[i]);
                        }
                    }
                }

                lview.setAdapter(new MyCustomAdapter(first_sort, second_sort));

            }
        });
    }

    class MyCustomAdapter extends BaseAdapter {

        String[] data_first;
        String[] data_second;

        {

        }

        MyCustomAdapter(String[] first, String[] second) {
            data_first = first;
            data_second = second;
        }

        MyCustomAdapter(ArrayList<String> first, ArrayList<String> second) {
            for (int i = 0; i < first.size(); i++) {
                data_first[i] = first.get(i);
                data_second[i] = second.get(i);
            }

        }

        public int getCount() {
            return data_first.length;
        }

        public String getItem(int position) {
            return null;
        }

        public long getItemId(int position) {
            return position;
        }

        public View getView(int position, View convertView, ViewGroup parent) {

            LayoutInflater inflater = getLayoutInflater();
            View row;

            row = inflater.inflate(R.layout.listitem_row, parent, false);

            TextView textview = (TextView) row.findViewById(R.id.textView1);
            TextView textview1 = (TextView) row.findViewById(R.id.textView2);

            textview.setText(data_first[position]);
            textview1.setText(data_second[position]);

                return (row);

           }
        }
    }
}

And this is the error I receive when I try to type a letter:

12-24 01:37:55.231: E/AndroidRuntime(15241): FATAL EXCEPTION: main
12-24 01:37:55.231: E/AndroidRuntime(15241): java.lang.NullPointerException
12-24 01:37:55.231: E/AndroidRuntime(15241): at it.gogle.com.Search$MyCustomAdapter.(Search.java:114)
12-24 01:37:55.231: E/AndroidRuntime(15241): at it.gogle.com.Search$2.onTextChanged(Search.java:87)
12-24 01:37:55.231: E/AndroidRuntime(15241): at android.widget.TextView.sendOnTextChanged(TextView.java:6240)
12-24 01:37:55.231: E/AndroidRuntime(15241): at android.widget.TextView.handleTextChanged(TextView.java:6281)
12-24 01:37:55.231: E/AndroidRuntime(15241): at android.widget.TextView$ChangeWatcher.onTextChanged(TextView.java:6456)
12-24 01:37:55.231: E/AndroidRuntime(15241): at android.text.SpannableStringBuilder.sendTextChange(SpannableStringBuilder.java:889)
12-24 01:37:55.231: E/AndroidRuntime(15241): at android.text.SpannableStringBuilder.change(SpannableStringBuilder.java:352)
12-24 01:37:55.231: E/AndroidRuntime(15241): at android.text.SpannableStringBuilder.change(SpannableStringBuilder.java:269)
12-24 01:37:55.231: E/AndroidRuntime(15241): at android.text.SpannableStringBuilder.replace(SpannableStringBuilder.java:432)
12-24 01:37:55.231: E/AndroidRuntime(15241): at android.text.SpannableStringBuilder.replace(SpannableStringBuilder.java:409)
12-24 01:37:55.231: E/AndroidRuntime(15241): at android.text.SpannableStringBuilder.replace(SpannableStringBuilder.java:28)
12-24 01:37:55.231: E/AndroidRuntime(15241): at android.view.inputmethod.BaseInputConnection.replaceText(BaseInputConnection.java:583)
12-24 01:37:55.231: E/AndroidRuntime(15241): at android.view.inputmethod.BaseInputConnection.commitText(BaseInputConnection.java:174)
12-24 01:37:55.231: E/AndroidRuntime(15241): at com.android.internal.widget.EditableInputConnection.commitText(EditableInputConnection.java:120)
12-24 01:37:55.231: E/AndroidRuntime(15241): at com.android.internal.view.IInputConnectionWrapper.executeMessage(IInputConnectionWrapper.java:247)
12-24 01:37:55.231: E/AndroidRuntime(15241): at com.android.internal.view.IInputConnectionWrapper$MyHandler.handleMessage(IInputConnectionWrapper.java:73)
12-24 01:37:55.231: E/AndroidRuntime(15241): at android.os.Handler.dispatchMessage(Handler.java:99)
12-24 01:37:55.231: E/AndroidRuntime(15241): at android.os.Looper.loop(Looper.java:123)
12-24 01:37:55.231: E/AndroidRuntime(15241): at android.app.ActivityThread.main(ActivityThread.java:4627)
12-24 01:37:55.231: E/AndroidRuntime(15241): at java.lang.reflect.Method.invokeNative(Native Method)
12-24 01:37:55.231: E/AndroidRuntime(15241): at java.lang.reflect.Method.invoke(Method.java:521)
12-24 01:37:55.231: E/AndroidRuntime(15241): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:858)
12-24 01:37:55.231: E/AndroidRuntime(15241): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616)
12-24 01:37:55.231: E/AndroidRuntime(15241): at dalvik.system.NativeStart.main(Native Method)

Thanks to every person who helps me.

  • 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-27T17:35:15+00:00Added an answer on May 27, 2026 at 5:35 pm

    I’m guessing that one of the sort parameters is null.

    Confirmed by OP comment, first_sort is null.


    As per this blog post, you need to:

    1. Save the values of all your class variables, including static variables in onSaveInstanceState(Bundle) to the bundle.
    2. Restore the variables from the bundle (if it’s not null) in onCreate(Bundle).

    See also:

    • Saving Android Activity state using Save Instance State
    • onSaveInstanceState () and onRestoreInstanceState ()

    …something like this (not tested):

    public class Search extends Activity {
        // snip...
    
        public void onCreate(Bundle savedInstanceState) {
            // snip...
    
            if (first_sort == null) {
                first_sort = savedInstanceState.getParcelableArrayList("first_sort");
            }
    
            if (second_sort == null) {
                second_sort = savedInstanceState.getParcelableArrayList("second_sort");
            }
        }
    
        // snip...
    
        @Override
        public void onSaveInstanceState(Bundle outState) {
            super.onSaveInstanceState(outState);
            outState.putParcelableArrayList("first_sort", first_sort);
            outState.putParcelableArrayList("second_sort", second_sort);
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am trying to understand how to use SyndicationItem to display feed which is
We're building an app, our first using Rails 3, and we're having to build
This could be a duplicate question, but I have no idea what search terms
I'm trying to select an H1 element which is the second-child in its group
I'm trying to convert HTML to plain text. I get many &\#8217; &\#8220; etc.
I am writing an app for my school newspaper, which is run completely online
Basically, what I'm trying to create is a page of div tags, each has
I am trying to find ID3V2 tags from MP3 file using jid3lib in Java.
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I have just tried to save a simple *.rtf file with some websites 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.