java.lang.NullPointerException AllSuggestionsActivity.onTextChanged (AllSuggestionsActivity.this.adapter.getFilter().filter(cs);)
<p>I am getting an error (<code>java.lang.NullPointerException</code>) when I execute the code for the <code>ListView</code> with <code>EditText</code> for filtering at the line </p>

<p><code>AllSuggestionsActivity.this.adapter.getFilter().filter(cs);</code> </p>

<p>kindly help.</p>

<pre><code>public class AllSuggestionsActivity extends ListActivity {

    EditText inputSearch;
    ListView lstList;

    // Progress Dialog
    private ProgressDialog pDialog;

    ArrayAdapter&lt;String&gt; adapter = null;

    // Creating JSON Parser object
    JSONParser jParser = new JSONParser();

    ArrayList&lt;HashMap&lt;String, String&gt;&gt; suggestionsList;

    // url to get all suggestions list
    private static String url_all_suggestions = "http://10.0.2.2/JKUAT-M-SUGGESTION-BOX/get_all_suggestions.php";

    // JSON Node names
    private static final String TAG_SUCCESS = "success";
    private static final String TAG_SUGGESTIONS = "suggestions";
    private static final String TAG_SID = "sid";
    private static final String TAG_SUBJECT = "subject";

    // suggestions JSONArray
    JSONArray suggestions = null;

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.all_suggestions);

        inputSearch = (EditText) findViewById(R.id.inputSearch);
        lstList = (ListView) findViewById(android.R.id.list);


        // Hashmap for ListView
        suggestionsList = new ArrayList&lt;HashMap&lt;String, String&gt;&gt;();

        // Loading suggestions in Background Thread
        new LoadAllSuggestions().execute();

        // Get listview
        ListView lv = getListView();

        /**
         * Enabling Search Filter
         * */
        inputSearch.addTextChangedListener(new TextWatcher() {

            @Override
            public void onTextChanged(CharSequence cs, int arg1, int arg2, int arg3) {
                // When user changed the Text
                AllSuggestionsActivity.this.adapter.getFilter().filter(cs);   
            }

            @Override
            public void beforeTextChanged(CharSequence arg0, int arg1, int arg2,
                    int arg3) {
                // TODO Auto-generated method stub

            }

            @Override
            public void afterTextChanged(Editable arg0) {
                // TODO Auto-generated method stub                          
            }
        });


        // on seleting single suggestion
        // launching Edit Suggestion Screen
        lv.setOnItemClickListener(new OnItemClickListener() {

            @Override
            public void onItemClick(AdapterView&lt;?&gt; parent, View view,
                    int position, long id) {
                // getting values from selected ListItem
                String sid = ((TextView) view.findViewById(R.id.sid)).getText()
                        .toString();

                // Starting new intent
                Intent in = new Intent(getApplicationContext(),
                        EditSuggestionActivity.class);
                // sending sid to next activity
                in.putExtra(TAG_SID, sid);

                // starting new activity and expecting some response back
                startActivityForResult(in, 100);
            }
        });

    }

    // Response from Edit Suggestion Activity
    @Override
    protected void onActivityResult(int requestCode, int resultCode, Intent data) {
        super.onActivityResult(requestCode, resultCode, data);
        // if result code 100
        if (resultCode == 100) {
            // if result code 100 is received
            // means user edited/deleted suggestion
            // reload this screen again
            Intent intent = getIntent();
            finish();
            startActivity(intent);
        }

    }

    /**
     * Background Async Task to Load all suggestion by making HTTP Request
     * */
    class LoadAllSuggestions extends AsyncTask&lt;String, String, String&gt; {

        /**
         * Before starting background thread Show Progress Dialog
         * */
        @Override
        protected void onPreExecute() {
            super.onPreExecute();
            pDialog = new ProgressDialog(AllSuggestionsActivity.this);
            pDialog.setMessage("Loading all suggestions. Please wait.......");
            pDialog.setIndeterminate(false);
            pDialog.setCancelable(false);
            pDialog.show();
        }

        /**
         * getting All suggestions from url
         * */
        @Override
        protected String doInBackground(String... args) {
            // Building Parameters
            List&lt;NameValuePair&gt; params = new ArrayList&lt;NameValuePair&gt;();
            // getting JSON string from URL
            JSONObject json = jParser.makeHttpRequest(url_all_suggestions,
                    "GET", params);

            // Check your log cat for JSON reponse
            Log.d("All Suggestions: ", json.toString());

            try {
                // Checking for SUCCESS TAG
                int success = json.getInt(TAG_SUCCESS);

                if (success == 1) {
                    // suggestions found
                    // Getting Array of Suggestions
                    suggestions = json.getJSONArray(TAG_SUGGESTIONS);

                    // looping through All Suggestions
                    for (int i = 0; i &lt; suggestions.length(); i++) {
                        JSONObject c = suggestions.getJSONObject(i);

                        // Storing each json item in variable
                        String id = c.getString(TAG_SID);
                        String subject = c.getString(TAG_SUBJECT);

                        // creating new HashMap
                        HashMap&lt;String, String&gt; map = new HashMap&lt;String, String&gt;();

                        // adding each child node to HashMap key =&gt; value
                        map.put(TAG_SID, id);
                        map.put(TAG_SUBJECT, subject);

                        // adding HashList to ArrayList
                        suggestionsList.add(map);
                    }
                } else {
                    // no suggestions found
                    Intent i = new Intent(getApplicationContext(),
                            MainScreenActivity.class);
                    // Closing all previous activities
                    i.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
                    startActivity(i);
                }
            } catch (JSONException e) {
                e.printStackTrace();
            }

            return null;
        }

        /**
         * After completing background task Dismiss the progress dialog
         * **/
        @Override
        protected void onPostExecute(String file_url) {
            // dismiss the dialog after getting all suggestions
            pDialog.dismiss();
            // updating UI from Background Thread
            runOnUiThread(new Runnable() {
                @Override
                public void run() {
                    /**
                     * Updating parsed JSON data into ListView
                     * */
                    ListAdapter adapter = new SimpleAdapter(
                            AllSuggestionsActivity.this, suggestionsList,
                            R.layout.list_item, new String[] { TAG_SID,
                                    TAG_SUBJECT }, new int[] { R.id.sid,
                                    R.id.subject });
                    // updating listview
                    setListAdapter(adapter);
                }
            });
        }
    }
}
</code></pre>

<p>xml code for the listview:</p>

<pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt;

&lt;ScrollView
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:fillViewport="true"&gt;    

    &lt;LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:orientation="vertical"&gt;

    &lt;EditText
        android:id="@+id/inputSearch"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_marginTop="5dp"
        android:ems="10"
        android:maxLines="1"
        android:hint="Search" &gt;
        &lt;requestFocus /&gt;
    &lt;/EditText&gt;--&gt;

        &lt;!-- Main ListView 
             Always give id value as list(@android:id/list)
        --&gt;
        &lt;ListView
            android:id="@android:id/list"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"/&gt;

    &lt;/LinearLayout&gt;


    enter code here

&lt;/ScrollView&gt;
</code></pre>
