title: Android get captured image meta data
body: <p>I am trying to capture the latitude of an image that has been captured through the camera and stored into the ImageBox variable. Using the ExifInterface class, I am trying to get the latitude of the image and display that information into the LatitudeBox variable but my syntax is incorrect so please let me know what I am doing wrong! full Code below</p>
  
  <p>MainActivity.java</p>
  
  <pre><code>import java.io.IOException;
  
  import android.app.Activity;
  import android.content.Intent;
  import android.graphics.Bitmap;
  import android.media.ExifInterface;
  import android.os.Bundle;
  import android.view.Menu;
  import android.view.View;
  import android.widget.Button;
  import android.widget.EditText;
  import android.widget.ImageView;
  
  public class MainActivity extends Activity {
      //variables
      Button CameraButton;
      ImageView ImageBox;
      EditText LatitudeBox, LongitudeBox;
      String IMG = ImageBox.toString();
  
      @Override
      protected void onCreate(Bundle savedInstanceState) {
          super.onCreate(savedInstanceState);
          setContentView(R.layout.activity_main);
  
          CameraButton = (Button) findViewById(R.id.CameraButton);
          ImageBox = (ImageView) findViewById(R.id.imageView1);
  
          LatitudeBox = (EditText) findViewById(R.id.LatitudeBox);
          LongitudeBox = (EditText) findViewById(R.id.LongitudeBox);
  
          //Camera Button Onclick
          CameraButton.setOnClickListener(new View.OnClickListener() {
  
              @Override
              public void onClick(View arg0) {
                  // TODO Auto-generated method stub
                  Intent intent = new Intent(android.provider.MediaStore.ACTION_IMAGE_CAPTURE);
                  startActivityForResult(intent, 0);
  
                  try {
                      ExifInterface exif = new ExifInterface(IMG);
                      LongitudeBox.setText(exif.getAttribute(ExifInterface.TAG_GPS_LONGITUDE_REF)); // get longitude
                      LatitudeBox.setText(exif.getAttribute(ExifInterface.TAG_GPS_LATITUDE_REF)); //get latitude 
                  } catch (IOException e) {
                      // TODO Auto-generated catch block
                      e.printStackTrace();
                  }// try catch 
              }// end onclick 
          });// end camera button onclick
  
  
  
  
  
      }// close oncreate
  
      //display image inside ImageBox variable using bitmap
      protected void onActivityResult(int requestCode, int resultCode, Intent data)
      {
          if(requestCode == 0)
          {
          Bitmap TheImage = (Bitmap) data.getExtras().get("data");
          ImageBox.setImageBitmap(TheImage);
          }
      }
  
      @Override
      public boolean onCreateOptionsMenu(Menu menu) {
          // Inflate the menu; this adds items to the action bar if it is present.
          getMenuInflater().inflate(R.menu.main, menu);
          return true;
      }
  
  
  
  
  
  
  
  }// close main
  </code></pre>
  
  <p>App now crashes on launch and not sure what's causing it. Here is an image of the logcat errors</p>
  
  <p><a href="http://s7.postimg.org/4p67papyj/logcat1.png" rel="nofollow">http://s7.postimg.org/4p67papyj/logcat1.png</a></p>
  
  <p>activity_main.XML </p>
  
  <p></p>
  
  <pre><code>&lt;ImageView
      android:id="@+id/imageView1"
      android:layout_width="250dp"
      android:layout_height="200dp"
      android:layout_alignParentTop="true"
      android:layout_centerHorizontal="true"
      android:layout_marginTop="32dp"
      android:src="@drawable/ic_launcher" /&gt;
  
  &lt;Button
      android:id="@+id/CameraButton"
      android:layout_width="150dp"
      android:layout_height="35dp"
      android:layout_below="@+id/imageView1"
      android:layout_centerHorizontal="true"
      android:layout_marginTop="38dp"
      android:text="@string/Camera_Button" /&gt;
  
  &lt;TextView
      android:id="@+id/LatitudeBox"
      android:layout_width="match_parent"
      android:layout_height="wrap_content"
      android:layout_below="@+id/CameraButton"
      android:layout_centerHorizontal="true"
      android:layout_marginTop="16dp"
      android:text="@string/LatitudeBox"
      android:textColor="#ff0000"
      android:textAppearance="?android:attr/textAppearanceLarge" /&gt;
  
  &lt;TextView
      android:id="@+id/LongitudeBox"
      android:layout_width="match_parent"
      android:layout_height="wrap_content"
      android:layout_below="@+id/LatitudeBox"
      android:layout_centerHorizontal="true"
      android:layout_marginTop="21dp"
      android:text="@string/LongitudeBox"
      android:textAppearance="?android:attr/textAppearanceLarge" /&gt;
  </code></pre>
  
  <p></p>