title: error while executing doInBackground
body: <h2>An error occured while executing doInBackground()</h2>
  <p>I am new to android studio and am trying to download different bitmap pictures to show in imageview by AsyncTask class.my error log follows:</p>
  <pre><code>FATAL EXCEPTION: AsyncTask #1
       Process: com.example.sayareh.http2, PID: 32302
          java.lang.RuntimeException: An error occured while executing doInBackground()
          at android.os.AsyncTask$3.done(AsyncTask.java:300)
          at java.util.concurrent.FutureTask.finishCompletion(FutureTask.java:355)
          at java.util.concurrent.FutureTask.setException(FutureTask.java:222)
          at java.util.concurrent.FutureTask.run(FutureTask.java:242)
          at android.os.AsyncTask$SerialExecutor$1.run(AsyncTask.java:231)
          at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1112)
          at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:587)
      at java.lang.Thread.run(Thread.java:818)
          Caused by: java.lang.RuntimeException: Can't create handler inside thread that has not called Looper.prepare()
          at android.os.Handler.&lt;init&gt;(Handler.java:200)
          at android.os.Handler.&lt;init&gt;(Handler.java:114)
          at android.widget.Toast$TN.&lt;init&gt;(Toast.java:561)
          at android.widget.Toast.&lt;init&gt;(Toast.java:129)
          at android.widget.Toast.makeText(Toast.java:419)
          at com.example.sayareh.http2.MainActivity.OpenHttpConnection(MainActivity.java:65)
          at com.example.sayareh.http2.MainActivity.DownloadImage(MainActivity.java:75)
          at com.example.sayareh.http2.MainActivity.access$100(MainActivity.java:32)
          at com.example.sayareh.http2.MainActivity$DownloadImageTask.doInBackground(MainActivity.java:87)
          at com.example.sayareh.http2.MainActivity$DownloadImageTask.doInBackground(MainActivity.java:83)
          at android.os.AsyncTask$2.call(AsyncTask.java:288)
      at java.util.concurrent.FutureTask.run(FutureTask.java:237)
          at android.os.AsyncTask$SerialExecutor$1.run(AsyncTask.java:231) 
          at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1112) 
          at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:587) 
          at java.lang.Thread.run(Thread.java:818) 
  </code></pre>
  <p>This is my MainActivityClass:</p>
  <pre><code>public class MainActivity extends AppCompatActivity {
  ImageView imageView;
  @Override
  protected void onCreate(Bundle savedInstanceState) {
      super.onCreate(savedInstanceState);
      setContentView(R.layout.activity_main);
      imageView=(ImageView) findViewById(R.id.img);
      new DownloadImageTask().execute(
              &quot;http://kocholo.org/img/images/lk4nnpetjq7rf10zf8r.jpg&quot;,
              &quot;http://media.mnn.com/assets/images/2016/01/stern-baby.jpg.838x0_q80.jpg&quot;,
              &quot;http://www.raisesmartkid.com/wp-content/uploads/baby-watching-tv.jpg&quot;,
              &quot;http://creativemisha.com/wp-content/uploads/2014/07/Cute-Baby-Girl-HD-Wallpaper1.jpg&quot;);
  
  }
  private InputStream OpenHttpConnection(String urlString) throws IOException {
      InputStream inputStream=null;
      int response=-1;
      URL url=new URL(urlString);
      URLConnection conn=url.openConnection();
      if(!(conn instanceof HttpURLConnection))
          throw  new IOException(&quot;Not an Http Connection&quot;);
      try {
          HttpURLConnection httpURLConnection=(HttpURLConnection) conn;
          httpURLConnection.setAllowUserInteraction(false);
          httpURLConnection.setInstanceFollowRedirects(true);
          httpURLConnection.setRequestMethod(&quot;GET&quot;);
          httpURLConnection.connect();
          response=httpURLConnection.getResponseCode();
          if(response==httpURLConnection.HTTP_OK)
              inputStream=httpURLConnection.getInputStream();
  
      }catch (Exception ex){
          Toast.makeText(this, &quot;NETWORKING&quot; + ex.getLocalizedMessage(), Toast.LENGTH_LONG).show();
          throw new IOException(&quot;errcoonnecting&quot;);
      }
      return inputStream;
  }
  private Bitmap DownloadImage(String url)
  {
      Bitmap bitmap=null;
      InputStream inputStream=null;
      try{
          inputStream=OpenHttpConnection(url);
          bitmap= BitmapFactory.decodeStream(inputStream);
          inputStream.close();
      }catch (IOException io){
          Toast.makeText(this,io.getLocalizedMessage(),Toast.LENGTH_LONG).show();
      }
      return bitmap;
  }
  private class DownloadImageTask extends AsyncTask&lt;String,Bitmap,Long&gt; {
      protected Long doInBackground(String... urls) {
          long imgcounts =0;
          for (int i = 0; i &lt; urls.length; i++) {
              Bitmap imagedownloaded = DownloadImage(urls[i]);
              if (imagedownloaded != null){
                  imgcounts++;
              try {
                  Thread.sleep(3000);
              } catch (InterruptedException ie) {
                  ie.printStackTrace();
              }
              publishProgress(imagedownloaded);
          }}
          return imgcounts;
      }
      protected void onProgressUpdate(Bitmap... bitmaps)
      {
          imageView.setImageBitmap(bitmaps[0]);
      }
  
      protected void onPostExecute(Long imagedownloaded) {
          Toast.makeText(getBaseContext(),&quot;h&quot;,Toast.LENGTH_LONG).show();
      }
  }
  </code></pre>
  <p>can anyone help me?</p>