I am trying to re-size an image, that part completed.
Then I’m trying to copy exif tags to new file.
I use ExifInterface to read tags.
I know it’s an interface not an object.
But When I try to use it for really big sized image, I get NullPointerException.
I get this error not for all the images.
07-25 11:59:23.870: WARN/System.err(1362): java.lang.NullPointerException
07-25 11:59:23.870: WARN/System.err(1362): at android.media.ExifInterface.saveAttributes(ExifInterface.java:202)
How do I solve it?
Code to copy exif information
try {
// copy paste exif information from original file to new
// file
ExifInterface oldexif = new ExifInterface(filePath);
ExifInterface newexif = new ExifInterface(file.getPath());
int build = Build.VERSION.SDK_INT;
// From API 11
if (build >= 11) {
newexif.setAttribute("FNumber",
oldexif.getAttribute("FNumber"));
newexif.setAttribute("ExposureTime",
oldexif.getAttribute("ExposureTime"));
newexif.setAttribute("ISOSpeedRatings",
oldexif.getAttribute("ISOSpeedRatings"));
}
// From API 9
if (build >= 9) {
newexif.setAttribute("GPSAltitude",
oldexif.getAttribute("GPSAltitude"));
newexif.setAttribute("GPSAltitudeRef",
oldexif.getAttribute("GPSAltitudeRef"));
}
// From API 8
if (build >= 8) {
newexif.setAttribute("FocalLength",
oldexif.getAttribute("FocalLength"));
newexif.setAttribute("GPSDateStamp",
oldexif.getAttribute("GPSDateStamp"));
newexif.setAttribute("GPSProcessingMethod",
oldexif.getAttribute("GPSProcessingMethod"));
newexif.setAttribute("GPSTimeStamp",
oldexif.getAttribute("GPSTimeStamp"));
}
newexif.setAttribute("DateTime",
oldexif.getAttribute("DateTime"));
newexif.setAttribute("Flash", oldexif.getAttribute("Flash"));
newexif.setAttribute("GPSLatitude",
oldexif.getAttribute("GPSLatitude"));
newexif.setAttribute("GPSLatitudeRef",
oldexif.getAttribute("GPSLatitudeRef"));
newexif.setAttribute("GPSLongitude",
oldexif.getAttribute("GPSLongitude"));
newexif.setAttribute("GPSLongitudeRef",
oldexif.getAttribute("GPSLongitudeRef"));
// You need to update this with your new height width
newexif.setAttribute("ImageLength",
oldexif.getAttribute("ImageLength"));
newexif.setAttribute("ImageWidth",
oldexif.getAttribute("ImageWidth"));
newexif.setAttribute("Make", oldexif.getAttribute("Make"));
newexif.setAttribute("Model", oldexif.getAttribute("Model"));
newexif.setAttribute("Orientation",
oldexif.getAttribute("Orientation"));
newexif.setAttribute("WhiteBalance",
oldexif.getAttribute("WhiteBalance"));
newexif.saveAttributes();
Toast.makeText(getApplicationContext(),
"Image resized & saved successfully",
Toast.LENGTH_SHORT).show();
} catch (Exception e) {
e.printStackTrace();
}
Additional onFly information:
New file is created when I’m trying to read both the file:

Debug watch on oldexif

Debug watch on newexif

Testing image
http://vikaskanani.files.wordpress.com/2011/07/test.jpg
Using Android emulator for sdk 2.1
You are passing a null value somewhere in the saveAttributes.
Debugging NullPointerExceptions is very easy, providing you have the sourcecode.
Below you can find the sourcecode for the ExifInterface for Android 2.1
http://grepcode.com/file/repository.grepcode.com/java/ext/com.google.android/android/2.1_r2/android/media/ExifInterface.java#ExifInterface
line 202 contains this :
Only thing that can be null here is val. (one of the values you’re passing in the saveAttributes method).
I would suggest double checking the values you’re passing onto that value, and watch out for null values.