1
File image = new File("/path/to/image/file");
FileInputStream fis = new FileInputStream(image);
BufferedImage originalImage = ImageIO.read(fis);
int height = originalImage.getHeight(); 

Exception -

Exception in thread "main" java.lang.NullPointerException
    at package.classfile.main(classfile.java:23)
Derrick
  • 3,669
  • 5
  • 35
  • 50
pavithra
  • 15
  • 6
  • on which line you are getting null pointer ? – Derrick Nov 19 '18 at 12:35
  • Could you provide a full stacktrace? – OhleC Nov 19 '18 at 12:48
  • Is `image` being created? `ImageIO.read` may require a specific type of file. From the docs: "Image I/O has built-in support for GIF, PNG, JPEG, BMP, and WBMP. Image I/O is also extensible so that developers or administrators can "plug-in" support for additional formats. For example, plug-ins for TIFF and JPEG 2000 are separately available." – SanSolo Nov 19 '18 at 12:51
  • 1
    Surely the null pointer is from ImageIO.read(fis). Javadocs: "If no registered ImageReader claims to be able to read the resulting stream, null is returned." Try to check the file first: image.exists() – vnkid Nov 19 '18 at 13:17
  • For better help sooner, [edit] to add a [MCVE] or [Short, Self Contained, Correct Example](http://www.sscce.org/). – Andrew Thompson Nov 19 '18 at 13:36

0 Answers0