title: retrieve image from mysql database in android studios
body: <p>I'm new to android studios. Here, I'm trying to fetch images from mysql database which is stored in a online server and displaying the image on listvew. But I'm getting error in my custom file. Please help me out. <a href="http://i.stack.imgur.com/fryuW.png" rel="nofollow">this is the error i'm getting in log when i try to run my application</a></p>
  
  <p>this is my customJava code:
  package com.example.manarpatel.book_app;</p>
  
  <pre><code>import android.app.Activity;
  import android.graphics.Bitmap;
  import android.view.LayoutInflater;
  import android.view.View;
  import android.view.ViewGroup;
  import android.widget.ArrayAdapter;
  import android.widget.ImageView;
  import android.widget.TextView;
  
  
  public class CustomList extends ArrayAdapter&lt;String&gt; {
  private String[] urls;
  private Bitmap[] bitmaps;
  private Activity context;
  
  public CustomList(Activity context, String[] urls, Bitmap[] bitmaps) {
      super(context, R.layout.image_list_view, urls);
      this.context = context;
      this.urls= urls;
      this.bitmaps= bitmaps;
  }
  
  @Override
  public View getView(int position, View convertView, ViewGroup parent) {
  
          LayoutInflater inflater = context.getLayoutInflater();
          View listViewItem = inflater.inflate(R.layout.image_list_view,parent, true);
  
          TextView textViewURL = (TextView) listViewItem.findViewById(R.id.textViewURL);
          ImageView image = (ImageView) listViewItem.findViewById(R.id.imageDownloaded);
  
          textViewURL.setText(urls[position]);
  
      Bitmap smaller = Bitmap.createScaledBitmap(bitmaps[position], 100, 50, false);
      image.setImageBitmap(smaller);
        //  image.setImageBitmap(Bitmap.createScaledBitmap(bitmaps[position], 100, 50, false));
  
      return listViewItem;
      }
  }
  </code></pre>
  
  <p>Here, is my imageList viewer java code:</p>
  
  <pre><code>package com.example.manarpatel.book_app;
  
  import android.app.ProgressDialog;
  import android.content.Intent;
  import android.os.AsyncTask;
  import android.os.Bundle;
  import android.support.v7.app.AppCompatActivity;
  import android.view.View;
  import android.widget.AdapterView;
  import android.widget.ListView;
  
  import org.json.JSONException;
  
  import java.io.BufferedReader;
  import java.io.InputStreamReader;
  import java.net.HttpURLConnection;
  import java.net.URL;
  
  
      public class ImageListView extends AppCompatActivity implements AdapterView.OnItemClickListener {
  
      private ListView listView;
  
      public static final String GET_IMAGE_URL="http://usedbookapp.esy.es/getAllImages.php";
  
      public GetAlImages getAlImages;
  
      public static final String BITMAP_ID = "BITMAP_ID";
  
      @Override
      protected void onCreate(Bundle savedInstanceState) {
          super.onCreate(savedInstanceState);
          setContentView(R.layout.activity_image_list_view);
  
          listView = (ListView) findViewById(R.id.listView);
          listView.setOnItemClickListener(this);
          getURLs();
      }
  
      private void getImages(){
          class GetImages extends AsyncTask&lt;Void,Void,Void&gt;{
              ProgressDialog loading;
              @Override
              protected void onPreExecute() {
                  super.onPreExecute();
                  loading = ProgressDialog.show(ImageListView.this,"Downloading images...","Please wait...",false,false);
              }
  
              @Override
              protected void onPostExecute(Void v) {
                  super.onPostExecute(v);
                  loading.dismiss();
                  //Toast.makeText(ImageListView.this,"Success",Toast.LENGTH_LONG).show();
                  CustomList customList = new CustomList(ImageListView.this,GetAlImages.imageURLs,GetAlImages.bitmaps);
                  listView.setAdapter(customList);
              }
  
              @Override
              protected Void doInBackground(Void... voids) {
                  try {
                      getAlImages.getAllImages();
  
                  } catch (JSONException e) {
                      e.printStackTrace();
                  }
                  return null;
              }
          }
          GetImages getImages = new GetImages();
          getImages.execute();
      }
  
      private void getURLs() {
          class GetURLs extends AsyncTask&lt;String,Void,String&gt;{
              ProgressDialog loading;
  
              @Override
              protected void onPreExecute() {
                  super.onPreExecute();
                  loading = ProgressDialog.show(ImageListView.this,"Loading...","Please Wait...",true,true);
              }
  
              @Override
              protected void onPostExecute(String s) {
                  super.onPostExecute(s);
                  loading.dismiss();
                  getAlImages = new GetAlImages(s);
                  getImages();
              }
  
              @Override
              protected String doInBackground(String... strings) {
                  BufferedReader bufferedReader = null;
                  try {
                      URL url = new URL(strings[0]);
                      HttpURLConnection con = (HttpURLConnection) url.openConnection();
                      StringBuilder sb = new StringBuilder();
  
                      bufferedReader = new BufferedReader(new InputStreamReader(con.getInputStream()));
  
                      String json;
                      while((json = bufferedReader.readLine())!= null){
                          sb.append(json+"\n");
                      }
  
                      return sb.toString().trim();
  
                  }catch(Exception e){
                      return null;
                  }
              }
          }
          GetURLs gu = new GetURLs();
          gu.execute(GET_IMAGE_URL);
      }
  
      @Override
          public void onItemClick(AdapterView&lt;?&gt; adapterView, View view, int i, long l) {
          Intent intent = new Intent(this, ViewFullImage.class);
          intent.putExtra(BITMAP_ID,i);
          startActivity(intent);
      }
  }
  </code></pre>
  
  <p>java code to get all images:</p>
  
  <pre><code>package com.example.manarpatel.book_app;
  
  
  import android.graphics.Bitmap;
  import android.graphics.BitmapFactory;
  
  import org.json.JSONArray;
  import org.json.JSONException;
  import org.json.JSONObject;
  
  import java.io.IOException;
  import java.net.MalformedURLException;
  import java.net.URL;
  
  public class GetAlImages {
  
  public static String[] imageURLs;
  public static Bitmap[] bitmaps;
  
  public static final String JSON_ARRAY="result";
  public static final String IMAGE_URL = "url";
  private String json;
  private JSONArray urls;
  
  public GetAlImages(String json){
      this.json = json;
      try {
          JSONObject jsonObject = new JSONObject(json);
          urls = jsonObject.getJSONArray(JSON_ARRAY);
      } catch (JSONException e) {
          e.printStackTrace();
      }
  }
  
  private Bitmap getImage(JSONObject jo){
      URL url = null;
      Bitmap image = null;
      try {
          url = new URL(jo.getString(IMAGE_URL));
          image = BitmapFactory.decodeStream(url.openConnection().getInputStream());
      } catch (MalformedURLException e) {
          e.printStackTrace();
      } catch (IOException e) {
          e.printStackTrace();
      } catch (JSONException e) {
          e.printStackTrace();
      }
      return image;
  }
  
  public void getAllImages() throws JSONException {
      bitmaps = new Bitmap[urls.length()];
  
      imageURLs = new String[urls.length()];
  
      for(int i=0;i&lt;urls.length();i++){
          imageURLs[i] = urls.getJSONObject(i).getString(IMAGE_URL);
          JSONObject jsonObject = urls.getJSONObject(i);
          bitmaps[i]=getImage(jsonObject);
          }
      }
  }
  </code></pre>
  
  <p>here,the xml code of image list view</p>
  
  <pre><code>&lt;LinearLayoutandroid:orientation="horizontal"android:layout_width="fill_parent" android:layout_height="wrap_content"&gt;
  &lt;ImageView android:id="@+id/imageDownloaded" android:layout_width="wrap_content" android:layout_height="wrap_content" android:src="@drawable/abc_ic_menu_copy_mtrl_am_alpha"/&gt;  
  &lt;TextView android:id="@+id/textViewURL" android:layout_width="wrap_content" android:layout_height="wrap_content"/&gt;
  
  &lt;/LinearLayout&gt;
  </code></pre>