title: Download a image from server to android and show in imageview
body: <p>I have an server (i use GlassFish). I am able to send Json or XML etc. with http to my android device. I saw an example to upload a picture from my android device to the server. That converts my picked image to byte, converts to String and back at my server. So i can put it on my PC (server). 
  Now i just want the opposite: get a picture from my PC and with the URL get the image (bitmap here) to imageview. but with debugging bmp seems to be "null". google says its because my image is not a valid bitmap (so maybe something is wrong at my server encoding?).
  What does i need to change to this code to get it working?</p>
  
  <p>Server code:</p>
  
  <pre><code>public class getImage{
      String imageDataString = null;
  
      @GET
      @Path("imageid/{id}")
      public String findImageById(@PathParam("id") Integer id) {
          //todo: schrijf een query voor het juiste pad te krijgen!
          System.out.println("in findImageById");
          File file = new File("C:\\Users\\vulst\\Desktop\\MatchIDImages\\Results\\R\\Tensile_Hole_2177N.tif_r.bmp");
  
          try{
              // Reading a Image file from file system
              FileInputStream imageInFile = new FileInputStream(file);
              byte imageData[] = new byte[(int) file.length()];
              imageInFile.read(imageData);
  
              // Converting Image byte array into Base64 String
              imageDataString = Base64.encodeBase64URLSafeString(imageData);
              imageInFile.close();
  
              System.out.println("Image Successfully Manipulated!");
          } catch (FileNotFoundException e) {
              System.out.println("Image not found" + e);
          } catch (IOException ioe) {
              System.out.println("Exception while reading the Image " + ioe);
          }
          return imageDataString;
  
      }
  
  }
  </code></pre>
  
  <p>and this is the android side (android studio):</p>
  
  <pre><code>public class XMLTask extends AsyncTask&lt;String, String, String&gt; {
  
      @Override
      protected String doInBackground(String... urls) {
          HttpURLConnection connection = null;
          BufferedReader reader = null;
          try {
              java.net.URL url = new URL(urls[0]);
              connection = (HttpURLConnection) url.openConnection();
              connection.connect();
              InputStream stream = connection.getInputStream();
              reader = new BufferedReader(new InputStreamReader(stream));
              StringBuffer buffer = new StringBuffer();
              String line = "";
              while ((line = reader.readLine()) != null) {
                  buffer.append(line);
              }
  
              return buffer.toString();
  
          } catch (MalformedURLException e) {
              e.printStackTrace();
          } catch (IOException e) {
              e.printStackTrace();
          } finally {
              if (connection != null) {
                  connection.disconnect();
              }
              try {
                  if (reader != null) {
                      reader.close();
                  }
              } catch (IOException e) {
                  e.printStackTrace();
              }
          }
          return null;
      }
  
      @Override
      protected void onPostExecute(String line) {
          super.onPostExecute(line);
          byte[] imageByteArray = Base64.decode(line , Base64.DEFAULT);
  
          try {
              Bitmap bmp = BitmapFactory.decodeByteArray(imageByteArray, 0, imageByteArray.length);
              ivFoto.setImageBitmap(bmp);
          }catch (Exception e){
              Log.d("tag" , e.toString());
          }
      }
  }
  </code></pre>