title: How to show image in android where image link is uploaded in mysql database
body: <p>newsshow.java</p>
  
  <pre><code>    package com.synergywebdesigners.nima;
  
      import android.app.Activity;
      import android.graphics.Bitmap;
      import android.graphics.BitmapFactory;
      import android.graphics.drawable.Drawable;
      import android.text.Html;
      import android.text.Spanned;
      import android.text.method.LinkMovementMethod;
      import android.util.Log;
      import android.view.LayoutInflater;
      import android.view.View;
      import android.view.ViewGroup;
      import android.widget.ArrayAdapter;
      import android.widget.ImageView;
      import android.widget.TextView;
  
      import com.squareup.picasso.Picasso;
  
      import java.io.IOException;
      import java.net.URL;
  
  
      public class newsshow  extends  ArrayAdapter&lt;String&gt; {
          private String[] ids;
          private String[] ttitle;
          private String[] tmessage;
          private String[] tcreated;
          private String[] picture;
          private Bitmap[] bitmaps;
          private Activity context;
  
  
  
          public newsshow(Activity context, String[] ids, String[] title, String[] picture,Bitmap[] bitmaps, String[] message, String[] created) {
              super(context, R.layout.list_view_layout, picture);
              this.context = context;
              this.ids = ids;
              this.ttitle = title;
              this.picture= picture;
              this.bitmaps= bitmaps;
              this.tmessage = message;
              this.tcreated = created;
          }
  
          @Override
          public View getView(int position, View convertView, ViewGroup parent) {
              LayoutInflater inflater = context.getLayoutInflater();
              View listViewItem = inflater.inflate(R.layout.list_view_layout, null, true);
              /// TextView id = (TextView) listViewItem.findViewById(R.id.id);
              TextView title = (TextView) listViewItem.findViewById(R.id.title);
              ImageView image = (ImageView) listViewItem.findViewById(R.id.imageDownloaded);
              TextView message = (TextView) listViewItem.findViewById(R.id.message);
              TextView created = (TextView) listViewItem.findViewById(R.id.created);
              //id.setText(ids[position]+".");
              title.setText(ttitle[position]);
              // spanned=Html.fromHtml(tmessage[position]);
   image.setImageBitmap(Bitmap.createScaledBitmap(bitmaps[position],100,50,true));
              message.setText(Html.fromHtml(tmessage[position]));
              created.setText(tcreated[position]);
              return listViewItem;
          }
      }
  </code></pre>
  
  <p>news.java</p>
  
  <pre><code>package com.synergywebdesigners.nima;
  
  import android.content.Intent;
  import android.os.Bundle;
  import android.support.v7.app.AppCompatActivity;
  import android.view.View;
  import android.widget.AdapterView;
  import android.widget.ListView;
  import android.widget.TextView;
  import android.widget.Toast;
  import com.android.volley.Response;
  import com.android.volley.VolleyError;
  import com.android.volley.toolbox.StringRequest;
  import com.android.volley.toolbox.Volley;
  
  
  
  public class news extends AppCompatActivity{
      public static final String JSON_URL = "http://www.synergywebdesigners.com/synergywebdesigners.com/ashish/nima/get_all_news.php";
      private ListView listView;
     // SharedPreferences pref;
      TextView textView,textview2,textview3;
      @Override
      protected void onCreate(Bundle savedInstanceState) {
          super.onCreate(savedInstanceState);
          setContentView(R.layout.activity_news);
        //  pref = getSharedPreferences("news", MODE_PRIVATE);
          final ListView list = (ListView) findViewById(R.id.listView);
          list.setOnItemClickListener(new AdapterView.OnItemClickListener() {
              @Override
              public void onItemClick(AdapterView&lt;?&gt; parent, View view, int position, long id) {
                // String item =  list.getItemAtPosition(position).toString();
                   textView = (TextView) view.findViewById(R.id.title);
                  textview2 = (TextView) view.findViewById(R.id.message);
                  textview3 = (TextView) view.findViewById(R.id.created);
                  String item2 = textView.getText().toString();
                  String item3 = textview2.getText().toString();
                  String item4 = textview3.getText().toString();
                  Intent i = new Intent(getApplicationContext(),newsview.class);
                  i.putExtra("item2",item2);
                  i.putExtra("item3",item3);
                  i.putExtra("item4",item4);
  
                  startActivity(i);
              }
          });
         listView = (ListView) findViewById(R.id.listView);
          sendRequest();
      }
      private void sendRequest() {
          StringRequest stringRequest = new StringRequest(JSON_URL, new Response.Listener&lt;String&gt;() {
              @Override
              public void onResponse(String response) {
                  showJSON(response);
              }
          },
                  new Response.ErrorListener() {
                      @Override
                      public void onErrorResponse(VolleyError error) {
                          Toast.makeText(news.this, error.getMessage(), Toast.LENGTH_SHORT).show();
                      }
                  });
  
          com.android.volley.RequestQueue requestQueue = Volley.newRequestQueue(this);
          requestQueue.add(stringRequest);
      }
      private void showJSON(String json) {
          ParseJSON pj = new ParseJSON(json);
          pj.parseJSON();
          newsshow cl = new newsshow(this, ParseJSON.ids, ParseJSON.ttitle, ParseJSON.picture,ParseJSON.bitmaps, ParseJSON.tmessage, ParseJSON.tcreated);
          listView.setAdapter(cl);
      }
  }
  </code></pre>
  
  <p>parsejason.java</p>
  
  <pre><code>package com.synergywebdesigners.nima;
  
  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;
  
  /**
   * Created by PC on 16-Dec-16.
   */
  
  public class ParseJSON {
      public static String[] ids;
      public static String[] ttitle;
      public static String[] tmessage;
      public static String[] tcreated;
      public static String[] picture;
      public static Bitmap[] bitmaps;
      public static final String JSON_ARRAY = "result";
      public static final String KEY_ID = "id";
      public static final String KEY_Title = "title";
      public static final String KEY_Message = "message";
      public static final String KEY_Created = "created";
      public static final String KEY_IMAGE ="picture";
      private JSONArray users = null;
  
      private String json;
  
      public ParseJSON(String json){
          this.json = json;
          try {
              JSONObject jsonObject = new JSONObject(json);
              users = 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(KEY_IMAGE));
              image = BitmapFactory.decodeStream(url.openConnection().getInputStream());
          } catch (MalformedURLException e) {
              e.printStackTrace();
          } catch (IOException e) {
              e.printStackTrace();
          } catch (JSONException e) {
              e.printStackTrace();
          }
          return image;
      }
      protected void parseJSON(){
          JSONObject jsonObject=null;
  
          try {
              jsonObject = new JSONObject(json);
              users = jsonObject.getJSONArray(JSON_ARRAY);
              ids = new String[users.length()];
              ttitle = new String[users.length()];
              bitmaps = new Bitmap[users.length()];
              picture = new String[users.length()];
              tmessage = new String[users.length()];
              tcreated = new String[users.length()];
              for(int i=0;i&lt;users.length();i++){
                  JSONObject jo = users.getJSONObject(i);
                  ids[i] = jo.getString(KEY_ID);
                  ttitle[i] = jo.getString(KEY_Title);
                  picture[i] = users.getJSONObject(i).getString(KEY_IMAGE);
                  bitmaps[i]= getImage(jo);
                  tmessage[i] = jo.getString(KEY_Message);
                  tcreated[i] = jo.getString(KEY_Created);
              }
          } catch (JSONException e) {
              e.printStackTrace();
          }
      }
  }
  </code></pre>
  
  <p>get_all_news.php </p>
  
  <pre><code>   &lt;?php
      define('HOST','localhost');
      define('USER','root');
      define('PASS','');
      define('DB','mrecord');
  
      $con = mysqli_connect(HOST,USER,PASS,DB);
  
      $sql = "select * from news ORDER BY created DESC LIMIT 100";
  
      $res = mysqli_query($con,$sql);
  
      $result = array();
  
      while($row = mysqli_fetch_array($res)){
      array_push($result,
      array('id'=&gt;$row[0],
      'title'=&gt;$row[1],
      'picture'=&gt;$row[2],
      'message'=&gt;$row[3],
      'created' =&gt;$row[4]
      ));
      }
  
      echo json_encode(array('result'=&gt;$result));
  
      mysqli_close($con);
      ?&gt;
  </code></pre>
  
  <hr>
  
  <p>newsshow.xml</p>
  
  <hr>
  
  <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt;
  &lt;LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
      xmlns:tools="http://schemas.android.com/tools"
      android:orientation="vertical"
      android:layout_width="match_parent"
      android:layout_height="match_parent"
      android:layout_marginLeft="2dp"
      android:layout_marginRight="2dp"
      android:layout_marginTop="10dp"&gt;
  
      &lt;!-- Title Label --&gt;
          &lt;TextView
              android:paddingLeft="20dp"
              android:layout_width="match_parent"
              android:layout_height="wrap_content"
              android:text="New Text"
              android:textAllCaps="true"
              android:textAppearance="?android:attr/textAppearanceMedium"
              android:textColor="#000000"
              android:textStyle="bold"
              android:id="@+id/title"
              android:gravity="center"/&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:layout_width="match_parent"
          android:layout_height="wrap_content"
          android:text="New Text"
          android:id="@+id/message"
          android:layout_marginLeft="20dp"
          android:layout_marginRight="10dp"
          android:layout_marginTop="10dp"/&gt;
      &lt;TextView
          android:layout_width="match_parent"
          android:layout_height="wrap_content"
          android:text="New Text"
          android:id="@+id/created"
          android:layout_marginLeft="20dp"/&gt;
  
  &lt;/LinearLayout&gt;
  </code></pre>
  
  <hr>
  
  <p>content_news.xml</p>
  
  <hr>
  
  <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt;
  &lt;RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
      xmlns:app="http://schemas.android.com/apk/res-auto"
      xmlns:tools="http://schemas.android.com/tools"
      android:id="@+id/content_news"
      android:layout_width="match_parent"
      android:layout_height="match_parent"
      android:paddingBottom="@dimen/activity_vertical_margin"
      android:paddingLeft="2dp"
      android:paddingRight="2dp"
      android:paddingTop="0dp"
      app:layout_behavior="@string/appbar_scrolling_view_behavior"
      tools:showIn="@layout/activity_news"&gt;
      &lt;ScrollView android:layout_height="match_parent"
          android:layout_width="match_parent"
          xmlns:android="http://schemas.android.com/apk/res/android"
          android:fillViewport="true"&gt;
  
  
              &lt;LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
                  xmlns:tools="http://schemas.android.com/tools"
                  android:layout_width="match_parent"
                  android:orientation="vertical"
                  android:layout_height="wrap_content"
                  android:paddingLeft="@dimen/activity_horizontal_margin"
                  android:paddingRight="@dimen/activity_horizontal_margin"
                  android:paddingTop="1dp"
                  android:paddingBottom="16dp"&gt;
  
                  &lt;ListView
                      android:layout_width="match_parent"
                      android:layout_height="wrap_content"
                      android:clickable="true"
                      android:id="@+id/listView" /&gt;
              &lt;/LinearLayout&gt;
          &lt;/ScrollView&gt;
  &lt;/RelativeLayout&gt;
  </code></pre>
  
  <hr>
  
  <p>activity_news.xml</p>
  
  <hr>
  
  <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt;
  &lt;android.support.design.widget.CoordinatorLayout xmlns:android="http://schemas.android.com/apk/res/android"
      xmlns:app="http://schemas.android.com/apk/res-auto"
      xmlns:tools="http://schemas.android.com/tools"
      android:layout_width="match_parent"
      android:layout_height="match_parent"
      android:fitsSystemWindows="true"
      tools:context="com.synergywebdesigners.nima.news"&gt;
  
      &lt;android.support.design.widget.AppBarLayout
          android:layout_width="match_parent"
          android:layout_height="wrap_content"
          android:theme="@style/AppTheme.AppBarOverlay"&gt;
  
      &lt;/android.support.design.widget.AppBarLayout&gt;
  
      &lt;include layout="@layout/content_news" /&gt;
  
  &lt;/android.support.design.widget.CoordinatorLayout&gt;
  </code></pre>
  
  <hr>
  
  <p>I want to take image from MySQL server and show image in android. But every times java Null Pointer exception created.</p>