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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 18, 20262026-05-18T12:46:13+00:00 2026-05-18T12:46:13+00:00

public class testMultiAutoCompleteTextView extends ListActivity { /** Called when the activity is first created.

  • 0
 public class testMultiAutoCompleteTextView extends ListActivity  {
/** Called when the activity is first created. */
private MultiAutoCompleteTextView searchEdit;
 Button   okButton;
private ArrayAdapter<String> adapter = null;

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    adapter = new ArrayAdapter<String>(this,
            android.R.layout.simple_list_item_1, mStrings);

   setListAdapter(adapter);

    searchEdit = (MultiAutoCompleteTextView) findViewById(R.id.search_box);

    searchEdit.addTextChangedListener(filterTextWatcher);

    searchEdit.setTokenizer(new SpaceTokenizer());

    searchEdit.setAdapter(adapter);

    searchEdit.setOnClickListener(new OnClickListener() {

        public void onClick(View v) {
            String t = ((TextView) v).getText().toString();
            String f = searchEdit.getText().toString();

            int s = searchEdit.getSelectionStart();
            int i = s;

            while (i > 0 && f.charAt(i - 1) != ' ') {
                i--;
            }

            adapter.getFilter().filter(t.substring(i, s));
        }
    });

    okButton = (Button) findViewById(R.id.ok);
    okButton.setOnClickListener(new OnClickListener() {

        public void onClick(View v) {
            Bundle stats = new Bundle();
            stats.putString("ConversationName", searchEdit.getText()
                    .toString());

            Intent i = new Intent();
            i.putExtras(stats);
            setResult(RESULT_OK, i);
            finish();
        }
    });

    searchEdit.setOnKeyListener(new OnKeyListener() {

        public boolean onKey(View v, int keyCode, KeyEvent event) {
            if (keyCode == KeyEvent.KEYCODE_DPAD_LEFT
                    || keyCode == KeyEvent.KEYCODE_DPAD_RIGHT
                    || keyCode == KeyEvent.KEYCODE_DPAD_UP
                    || keyCode == KeyEvent.KEYCODE_DPAD_DOWN) {

                String t = ((TextView) v).getText().toString();
                String f = searchEdit.getText().toString();

                int s = searchEdit.getSelectionStart();
                int i = s;

                while (i > 0 && f.charAt(i - 1) != ' ') {
                    i--;
                }

                adapter.getFilter().filter(t.substring(i, s));

                return false;
            }

            return false;
        }
    });

    getListView().setOnItemClickListener(
            new ListView.OnItemClickListener() {
                public void onItemClick(AdapterView<?> parent, View view,
                        int position, long id) {

                    String t = adapter.getItem(position);
                    String f = searchEdit.getText().toString();

                    int s = searchEdit.getSelectionStart();
                    int i = s;

                    while (i > 0 && f.charAt(i - 1) != ' ') {
                        i--;
                    }

                    searchEdit.getText().insert(s, t.substring(s - i));
                }
            });
}


    @Override
protected void onDestroy() {
    super.onDestroy();
    searchEdit.removeTextChangedListener(filterTextWatcher);
}


private TextWatcher filterTextWatcher = new TextWatcher() {

    public void afterTextChanged(Editable s) {
        okButton.setEnabled(searchEdit.getText().toString().trim()
                .length() > 0);
    }

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

    public void onTextChanged(CharSequence s, int start, int before,
            int count) {
        adapter.getFilter().filter(s);
    }

};



public class SpaceTokenizer implements Tokenizer {

public int findTokenStart(CharSequence text, int cursor) {
    int i = cursor;

    while (i > 0 && text.charAt(i - 1) != ' ') {
        i--;
    }
    while (i < cursor && text.charAt(i) == ' ') {
        i++;
    }

    return i;
}

public int findTokenEnd(CharSequence text, int cursor) {
    int i = cursor;
    int len = text.length();

    while (i < len) {
        if (text.charAt(i) == ' ') {
            return i;
        } else {
            i++;
        }
    }

    return len;
}

public CharSequence terminateToken(CharSequence text) {
    int i = text.length();

    while (i > 0 && text.charAt(i - 1) == ' ') {
        i--;
    }

    if (i > 0 && text.charAt(i - 1) == ' ') {
        return text;
    } else {
        if (text instanceof Spanned) {
            SpannableString sp = new SpannableString(text + " ");
            TextUtils.copySpansFrom((Spanned) text, 0, text.length(),
                    Object.class, sp, 0);
            return sp;
        } else {
            return text + " ";
        }
    }
}
}
 private String[] mStrings = {

            "Vacherin-Fribourgeois", "Valencay", "Vasterbottenost", "Venaco", "Vendomois",
            "Vieux Corse", "Vignotte", "Vulscombe", "Waimata Farmhouse Blue",
            "Washed Rind Cheese (Australian)", "Waterloo", "Weichkaese", "Wellington",
            "Wensleydale", "White Stilton", "Whitestone Farmhouse", "Wigmore", "Woodside Cabecou",
            "Xanadu", "Xynotyro", "Yarg Cornish", "Yarra Valley Pyramid", "Yorkshire Blue",
            "Zamorano", "Zanetti Grana Padano", "Zanetti Parmigiano Reggiano"};

}
my xml:

   <?xml version="1.0" encoding="utf-8"?>
   <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
      android:layout_width="fill_parent" android:layout_height="fill_parent"
       android:orientation="vertical"
       android:drawingCacheQuality="high">

   <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
       android:layout_width="fill_parent" android:layout_height="wrap_content"
       android:orientation="horizontal">


<MultiAutoCompleteTextView
    android:layout_marginLeft="1dip"
    android:layout_marginTop="1dip"
    android:layout_height="wrap_content" 
    android:layout_weight="1"
    android:layout_width="fill_parent"
    android:dropDownHeight="0px" 
    android:hint="@string/To" 
    android:id="@+id/search_box"
    ></MultiAutoCompleteTextView>



<Button android:layout_width="wrap_content"
    android:layout_height="wrap_content" 
    android:text="Ok"
    android:id="@+id/ok"
    android:enabled="false"
    />  


  </LinearLayout>     
  <ListView android:id="@android:id/list" android:layout_width="fill_parent"
    android:layout_height="fill_parent" android:layout_weight="1" />

    </LinearLayout>

it give me ERROR/AndroidRuntime(423): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.test.testMultiAutoCompleteTextView/com.test.testMultiAutoCompleteTextView.testMultiAutoCompleteTextView}: java.lang.NullPointerException

  • 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-18T12:46:14+00:00Added an answer on May 18, 2026 at 12:46 pm

    at onCreate method before to call

    adapter = new ArrayAdapter<String>(this,
            android.R.layout.simple_list_item_1, mStrings);
    

    you have to set you layout

    setContentView(R.layout.you_xml_file_name);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

public class Battery1 extends Activity { /** Called when the activity is first created.
public class Greeter extends MovieClip { public function Greeter() { addEventListener(Event.ADDED_TO_STAGE, go); } private
public class SuperUser extends User implements Serializable{ private static final long serialVersionUID = 1L;
public class MainFrame extends JFrame { MainFrame() { JButton zeroButton = new JButton(0); add(zeroButton);
public class Student implements java.io.Serializable { private long studentId; private String studentName; private Set<Course>
public class TwoBridge implements Piece{ private HashSet<Hexagon>[] permutations; public TwoBridge(){ permutations = new HashSet<Hexagon>[6];
public class MainFrame extends JFrame { public DefaultTableModel historyModel; public DefaultTableModel dataModel; public JTable
public class SomeClass { private HashSet<SomeObject> contents = new HashSet<SomeObject>(); private Set<SomeObject> contents2 =
public class ReportView extends JFrame { Connection con=null; void showReport() throws SQLException, ClassNotFoundException, JRException
public class AllViewModel { private List<Settings> SettingsList; public ViewAgendaAllViewModel() { client.SupplierListWithSettings(GetSupplierListWithSettings_Completed) } public void

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.