title: Autocomplete Text is not working in android fragment
body: <p>I want to set autocomplete text in my application. The suggestion values will fetch from the database. But for a trial I made a string array for the suggestion values. It works fine when I implement it on an activity but not working in fragment.</p>
  
  <p>In place of getActivity function I tried:<br>
  1) getContext()<br>
  2) this.getActivity()<br>
  3) (Search_Bus)getActivity()  </p>
  
  <p>but none work...
  it's giving me error:</p>
  
  <blockquote>
    <p>Attempt to invoke virtual method on a null object reference</p>
  </blockquote>
  
  <p>Here's my code...</p>
  
  <pre><code>public class Bus_Schedule_tab3 extends Fragment {
  
  AutoCompleteTextView autoCompleteTextView;
  ArrayList&lt;String&gt; array;
  ArrayAdapter&lt;String&gt; adapter;
  String[] stop_names;
  
      public View onCreateView(LayoutInflater inflater, ViewGroup container,
                           Bundle savedInstanceState) {
      View rootView = inflater.inflate(R.layout.bus_schedule_tab3, container, false);
  
      stop_names  = new String[] {"usa","china","russia","bangladesh"};
  
      autoCompleteTextView = (AutoCompleteTextView)rootView.findViewById(R.id.autoCompleteTextView2);
      adapter = new ArrayAdapter&lt;String&gt;(getActivity(),R.layout.support_simple_spinner_dropdown_item,stop_names);
      autoCompleteTextView.setAdapter(adapter);
  
      return rootView;
  }
  </code></pre>