title: AsyncTask to update adapter UI
body: <p>im pretty new to Android and <code>AsyncTask</code> and was hoping you could help...Im trying to refresh an ImageView adapter so it updates on the UI... i was told to use <code>notifyDataSetChanged()</code> but i just can get it to work...i have setup an asynctask but the only result i get is a <strong>NullPointerException</strong>...i need the update to happen when a new element is added to my <em>nextColorArray</em>....Please look at my code, i seriously dont even know if im using my asynctask in the right manner or if im even close?!..cheers</p>
  
  <pre><code>public class GameScreen extends Activity{
  int yellow = 0xffffff66;
  int green = 0xff00EE76;
  int red = 0xffff4342;
  int blue = 0xff42c3ff;
  int purple = 0xff9932CC;
  int white = 0xFFFFFFFF;
  
  int total_Count = 0;
  int colorPosition = 0;//nextColor position
  int colorPickerStart = 0;
  ArrayList&lt;Integer&gt;nextColorArray;
  ImageView imageView;
  ImageAdapter ia;  
  private static final String TAG = GameScreen.class.getSimpleName();//log
  
  ArrayList&lt;Integer&gt;colorPicker = new ArrayList&lt;Integer&gt;();
  
  @Override
  protected void onCreate(Bundle savedInstanceState) {
      super.onCreate(savedInstanceState);
      setContentView(R.layout.game_screen);
      new upDateNextColor().execute();
  }
  
  class upDateNextColor extends AsyncTask&lt;Void, Void, Void&gt; {
  
      GridView gridview2;
  
      @Override
      protected Void doInBackground(Void... voids) {
          return null;
      }
      @Override
      protected void onPostExecute(Void result) {
          nextColorArray.add(blue);
          nextColorArray.add(green);
          nextColorArray.add(red);
          nextColorArray.add(yellow);
          nextColorArray.add(purple);
          Collections.shuffle(nextColorArray);
      }
  
      @Override
      protected void onPreExecute() {
          nextColorArray = new ArrayList&lt;Integer&gt;(10);
          gridview2 = (GridView) findViewById(R.id.colorNext);
          ia = new ImageAdapter(nextColorArray);
          gridview2.setAdapter(ia);
          if(total_count &gt; 10){
          nextColorArray.add(0, white);
          ia.notifyDataSetChanged();
          }           
      }
   }
  
   public class ImageAdapter extends BaseAdapter {
      private Context mContext;
      private ArrayList aL;
  
      public ImageAdapter(Context c, ArrayList&lt;Integer&gt;aL) {
          mContext = c;
          this.aL = aL;
      }
  
      public ImageAdapter(ArrayList&lt;Integer&gt;aL) {
          this.aL = aL;
      }
  
      public ImageAdapter(Context c){
          mContext = c;
      }
  
      public int getCount() {
  
          return 10;
      }
  
      public Object getItem(int position) {
          return null;
      }
  
      public long getItemId(int position) {
          return 0;
      }
  
      public View getView(int position, View convertView, ViewGroup parent) {
          if (convertView == null) {
              imageView = new ImageView(mContext);
              imageView.setLayoutParams(new GridView.LayoutParams(50, 50));
              imageView.setBackgroundColor(nextColorArray.get(colorPosition));
              if(colorPosition &lt; 9) colorPosition++;
          } else {
              imageView = (ImageView) convertView;
          }
          return imageView;
      }
  }
  </code></pre>
  
  <p><strong>Logcat</strong></p>
  
  <pre><code>E/AndroidRuntime: FATAL EXCEPTION: main java.lang.NullPointerException
  at android.view.ViewConfiguration.get(ViewConfiguration.java:332)
  at android.view.View.&lt;init&gt;(View.java:3254)
  at android.widget.ImageView.&lt;init&gt;(ImageView.java:105)
  </code></pre>