title: NullPointerException when setting textView.setAdapter(
body: <p>This should be pretty simple, still I can not see what/how something could be Null.
  I have trying to have a <strong>AutoCompleteTextView</strong> with result from google places api.
  I can see that my URL creation is correct, I am getting results from google but when the result is being propagated to the textView, everything crashes.</p>
  
  <p>XML Layout - places_search.xml:</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt;
  
  &lt;RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
      android:layout_width="fill_parent"
      android:layout_height="fill_parent"
      android:background="#dddddd"&gt;
  
  &lt;AutoCompleteTextView android:id="@+id/autoCompleteTextView1"
      android:layout_width="fill_parent"
      android:layout_height="wrap_content"
      android:layout_marginTop="10dp" &gt;
      &lt;requestFocus&gt;&lt;/requestFocus&gt;
      &lt;/AutoCompleteTextView&gt;
  &lt;/RelativeLayout&gt;
  </code></pre>
  
  <p>XML layout for TextView:</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt;
  &lt;TextView xmlns:android="http://schemas.android.com/apk/res/android"
      android:layout_width="fill_parent"
      android:layout_height="fill_parent"
      android:padding="10dp"
      android:textSize="16sp"
      android:textColor="#000"&gt;
  &lt;/TextView&gt;
  </code></pre>
  
  <p>And below is the complete code which search for auto-completion results from google places api.</p>
  
  <pre><code>public class PlacesListSearchActivity extends Activity {
  
      private static final String TAG = "PlacesListActivity";
  
      private ResultReceiver mReceiver;
  
      private OnSharedPreferenceChangeListener sharedPreferencesListener;
      private SharedPreferences sharedPreferences;
  
      /** Called when the activity is first created. */
      public ArrayAdapter&lt;String&gt; adapter;
      public AutoCompleteTextView textView;
  
      @Override
      public void onCreate(Bundle savedInstanceState) {
          super.onCreate(savedInstanceState);
          setContentView(R.layout.places_search);
          final ArrayAdapter&lt;String&gt; adapter = new ArrayAdapter&lt;String&gt;(this,R.layout.item_list);
          final AutoCompleteTextView textView = (AutoCompleteTextView)findViewById(R.id.autoCompleteTextView1);
          adapter.setNotifyOnChange(true);
          textView.setHint("type store name");
          textView.setAdapter(adapter);
          textView.addTextChangedListener(new TextWatcher() {
  
          public void onTextChanged(CharSequence s, int start, int before, int count) {
              if (count%3 == 1) {
                  adapter.clear();
                      GetPlaces task = new GetPlaces();
                      //now pass the argument in the textview to the task
                      task.execute(textView.getText().toString());
              }
          }
  
          public void beforeTextChanged(CharSequence s, int start, int count,
          int after) {
          // TODO Auto-generated method stub
  
          }
  
          public void afterTextChanged(Editable s) {
  
          }
  
          });
      }
  
      class GetPlaces extends AsyncTask&lt;String, Void, ArrayList&lt;String&gt;&gt; {
          @Override
          // three dots is java for an array of strings
          protected ArrayList&lt;String&gt; doInBackground(String... args)
          {
              Log.d("gottaGo", "doInBackground");
              ArrayList&lt;String&gt; predictionsArr = new ArrayList&lt;String&gt;();
              try
              {
                  URL googlePlaces = new URL(
                          "https://maps.googleapis.com/maps/api/place/autocomplete/json?input=" +
                          URLEncoder.encode(args[0], "UTF-8") +
                          "&amp;types=geocode&amp;language=en&amp;sensor=true&amp;key=" +
                          getResources().getString(R.string.googleAPIKey));
  
                  Log.d("URL", googlePlaces.toString());
  
                  URLConnection tc = googlePlaces.openConnection();
                  BufferedReader in = new BufferedReader(new InputStreamReader(
                          tc.getInputStream()));
  
                  String line;
                  StringBuffer sb = new StringBuffer();
                  //take Google's legible JSON and turn it into one big string.
                  while ((line = in.readLine()) != null) {
                      sb.append(line);
                  }
                  //turn that string into a JSON object
                  JSONObject predictions = new JSONObject(sb.toString()); 
                  //now get the JSON array that's inside that object            
                  JSONArray ja = new JSONArray(predictions.getString("predictions"));
  
                  for (int i = 0; i &lt; ja.length(); i++) {
                      JSONObject jo = (JSONObject) ja.get(i);
                      //add each entry to our array
                      predictionsArr.add(jo.getString("description"));
                  }
              } catch (IOException e)
              {
              Log.e("YourApp", "GetPlaces : doInBackground", e);
              } catch (JSONException e)
              {
  
  
      Log.e("YourApp", "GetPlaces : doInBackground", e);
          }
  
          return predictionsArr;
      }
  
      //then our post
      @Override
      protected void onPostExecute(ArrayList&lt;String&gt; result){
          Log.d("YourApp", "onPostExecute : " + result.size());
          //update the adapter
          adapter = new ArrayAdapter&lt;String&gt;(getBaseContext(), R.layout.item_list);
          adapter.setNotifyOnChange(true);
          //attach the adapter to textview
          textView.setAdapter(adapter);
  
          for (String string : result) {
              Log.d("YourApp", "onPostExecute : result = " + string);
              adapter.add(string);
              adapter.notifyDataSetChanged();
          }
  
          Log.d("YourApp", "onPostExecute : autoCompleteAdapter" + adapter.getCount());
      }
  
  }
  
  }
  </code></pre>
  
  <p>below is the LOGCAT:</p>
  
  <pre><code>06-24 09:34:41.225: E/AndroidRuntime(10588): FATAL EXCEPTION: main
  06-24 09:34:41.225: E/AndroidRuntime(10588): java.lang.NullPointerException
  06-24 09:34:41.225: E/AndroidRuntime(10588):    at com.rathinavelu.rea.PlacesListSearchActivity$GetPlaces.onPostExecute(PlacesListSearchActivity.java:156)
  06-24 09:34:41.225: E/AndroidRuntime(10588):    at com.rathinavelu.rea.PlacesListSearchActivity$GetPlaces.onPostExecute(PlacesListSearchActivity.java:1)
  06-24 09:34:41.225: E/AndroidRuntime(10588):    at android.os.AsyncTask.finish(AsyncTask.java:602)
  06-24 09:34:41.225: E/AndroidRuntime(10588):    at android.os.AsyncTask.access$600(AsyncTask.java:156)
  06-24 09:34:41.225: E/AndroidRuntime(10588):    at android.os.AsyncTask$InternalHandler.handleMessage(AsyncTask.java:615)
  06-24 09:34:41.225: E/AndroidRuntime(10588):    at android.os.Handler.dispatchMessage(Handler.java:99)
  06-24 09:34:41.225: E/AndroidRuntime(10588):    at android.os.Looper.loop(Looper.java:137)
  06-24 09:34:41.225: E/AndroidRuntime(10588):    at android.app.ActivityThread.main(ActivityThread.java:4507)
  06-24 09:34:41.225: E/AndroidRuntime(10588):    at java.lang.reflect.Method.invokeNative(Native Method)
  06-24 09:34:41.225: E/AndroidRuntime(10588):    at java.lang.reflect.Method.invoke(Method.java:511)
  06-24 09:34:41.225: E/AndroidRuntime(10588):    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:790)
  06-24 09:34:41.225: E/AndroidRuntime(10588):    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:557)
  06-24 09:34:41.225: E/AndroidRuntime(10588):    at dalvik.system.NativeStart.main(Native Method)
  </code></pre>
  
  <p>Line 156 takes me to this line in the code:</p>
  
  <pre><code>textView.setAdapter(adapter);
  </code></pre>