title: How to display image (byte array) from JSON into imageView... Factory returns null
body: <p>I'm struggling with this problem 2 days already... Was posting before but non of the answers were right.</p>
  
  <p>My problem is: i'm trying to convert byte[] into image. The byte[] comes from JSON and it's in this format:</p>
  
  <p>"4oCwUE5HDQoaCgAAAA1JSERSAAAAfwAAAFAIBgAAADBHwqrDsAAAAAlwSFlzAAAAJwAAACcBKgnigJhPAAAgAElEQVR4xZPCrMK9ecWSZcOZfcOfw7c5w5vCvW/CqXp..." it goes for another 100 lines.</p>
  
  <p>Class for displaying the images: </p>
  
  <pre><code>public class PlayersListActivity extends Activity {
  
  // URL to make request
  private static String URL = "url goes here";
  private static int userID;
  ArrayList&lt;HashMap&lt;String, Object&gt;&gt; playersList;
  ListView playerView;
  
  @Override
  protected void onCreate(Bundle savedInstanceState) {
      super.onCreate(savedInstanceState);
      setContentView(R.layout.list_view);
  
      Bundle extras = getIntent().getExtras();
      userID = extras.getInt("id");
      initLayout();
  }
  
  private void initLayout() {
  
      playerView = (ListView) findViewById(R.id.list);
      playersList = new ArrayList&lt;HashMap&lt;String, Object&gt;&gt;();
  
      playerView.setAdapter(new SimpleAdapter(PlayersListActivity.this, playersList, R.layout.activity_players_list, null, null));
  
  
      playerView.setDividerHeight(0);
  
  }
  
  @Override
  protected void onResume() {
      if (!ConnectivityStatus.isNetworkAvailable(getApplicationContext())) {
          Toast.makeText(PlayersListActivity.this, R.string.network_failed,
                  Toast.LENGTH_SHORT).show();
      } else {
          playerView.setAdapter(null);
          new PlayersLoadTask().execute();
      }
  
      super.onResume();
  }
  
  ProgressDialog pDialog;
  
  class PlayersLoadTask extends AsyncTask&lt;String, String, String&gt; {
  
      @Override
      protected void onPreExecute() {
          super.onPreExecute();
          pDialog = new ProgressDialog(PlayersListActivity.this);
          pDialog.setMessage("Reading data");
          pDialog.setIndeterminate(false);
          pDialog.setCancelable(true);
          pDialog.show();
          playersList.clear();
      }
      @Override
      protected String doInBackground(String... arg0) {
          try {
  
          ArrayList&lt;BasicNameValuePair&gt; parameters = new ArrayList&lt;BasicNameValuePair&gt;();
          parameters.add(new BasicNameValuePair("request", "getPlayers"));
          parameters.add(new BasicNameValuePair("clubid", Integer.toString(userID))); // TODO: you'll need to change this to the Id from the user
  
          DefaultHttpClient httpClient = new DefaultHttpClient();
          HttpPost httpPost = new HttpPost(PlayersListActivity.URL);
          httpPost.setEntity(new UrlEncodedFormEntity(parameters, "UTF-8"));
          HttpResponse httpResponse = httpClient.execute(httpPost);
          HttpEntity httpEntity = httpResponse.getEntity();
  
          // if this is null the web service returned an empty page
          if(httpEntity == null) // response is empty so exit out
              return null;
  
          String jsonString = EntityUtils.toString(httpEntity);
  
          // again some simple validation around the returned string
          if(jsonString != null &amp;&amp; jsonString.length() != 0) // checking string returned from service to grab id
          {
              JSONArray jsonArray = new JSONArray(jsonString);
              for(int i=0; i&lt; jsonArray.length(); i++)
              {   
                  HashMap&lt;String, Object&gt; map = new HashMap&lt;String, Object&gt;();
  
                  JSONObject jsonObject = (JSONObject) jsonArray.get(i);
                  int id = jsonObject.getInt("id");
                  String name = jsonObject.getString("name");
                  byte[] image = jsonObject.getString("image").getBytes();
                  String base64 = jsonObject.getString("image");
                  try {
                      BitmapFactory.Options op=new BitmapFactory.Options();
                      op.inSampleSize=8;
                      Bitmap yourSelectedImage = BitmapFactory.decodeByteArray(image,0,image.length);
                      ByteArrayOutputStream baos = new ByteArrayOutputStream(); 
  
                      yourSelectedImage.compress(Bitmap.CompressFormat.PNG, 100, baos);
                      //this will convert image to byte[] 
                      byte[] byteArrayImage = baos.toByteArray(); 
                      // this will convert byte[] to string
                      String encodedImage = Base64.encodeToString(byteArrayImage, Base64.DEFAULT);
                      if (encodedImage != null) {
  
                         ImageView imgView = (ImageView) findViewById(R.id.image);
                         imgView.setImageBitmap(yourSelectedImage);
                      }
  
                  } catch (Exception e) {
                      Log.d("Exception", e.toString());
                  }
                  //map.put("id", id);
                  map.put("image", base64.toString());
                  map.put("name", name);
  
                  //Log.d("JSON OBJECTS:", jsonObject.toString());
                  //Log.d("WHATS IN MAP:", map.toString());
  
                  playersList.add(map);
              }
  
          }
      } catch (UnsupportedEncodingException e) {
          e.printStackTrace();
      } catch (ClientProtocolException e) {
          e.printStackTrace();
      } catch (IOException e) {
          e.printStackTrace();
      } catch (JSONException e) {
          e.printStackTrace();
      } catch (Exception e) {
          Log.e("ERROR SOMEWHERE!!!! " , e.toString());
      }
      return null;
  
      }
  
      protected void onPostExecute(String file_url) {
          if(playersList.size() == 0 ) {
              Toast.makeText(PlayersListActivity.this, "No players in a list" , Toast.LENGTH_SHORT).show();
          } else {
              playerView.setAdapter(new PlayerListAdapter (PlayersListActivity.this, playersList, R.layout.activity_players_list, new String[] {"id", "image", "name"}, new int[] {R.id.player_list_id, R.id.image, R.id.name, }));
          }
  
          pDialog.dismiss();
      } 
  }
  </code></pre>
  
  <p>}</p>
  
  <p>And the LogCat: </p>
  
  <pre><code> D/skia(3513): --- SkImageDecoder::Factory returned null
   D/skia(3513): --- SkImageDecoder::Factory returned null
   E/BitmapFactory(4399): Unable to decode stream: java.io.FileNotFoundException: /4oCwUE5HDQoaCgAAAA1JSERSAAAAfwAAAFAIBgAAADBHwqrDsAAAAAlwSFlzAAAAJwAAACcBKgnigJhPAAAgAElEQVR4xZPCrMK9ecWSZcOZfcOfw7c5w5vCvW/CqXpLV...
  </code></pre>
  
  <p>I have no idea at all why my Bitmap return null. I have tried many different ways but nothing works.</p>
  
  <p>That's why I need help badly! Thanks!!!</p>