-1

Currently trying to pass an InputSteam to Java's ImageIO by providing a URL().openStream().

val sourceIO = new URL(fileName).openStream()
val bufferedImage = ImageIO.read(sourceIO)

I am testing around 100 different images. I know each image exists because when I pass the same input steam to a different class, it works just fine. However, ImageIO keeps complaining the stream is null: java.lang.IllegalArgumentException: input == null!

My suspicion is that something is not properly initializing. Any idea how to fix this? Thanks!

crockpotveggies
  • 12,682
  • 12
  • 70
  • 140

1 Answers1

0

Discovered the problem. It actually was because I was using a val sourceIO assuming the input stream was re-usable. By changing val to def I was able to pass a fresh input stream to the ImageIO object.

Note: this wasn't working properly because sourceIO was already referenced before it was passed to ImageIO, thus the stream was null.

crockpotveggies
  • 12,682
  • 12
  • 70
  • 140