1

When using ICODecoder.read(new File("path")); in IntelliJ IDEA the read is underlined in read and states "java: unreported exception java.io.IOException; must be caught or declared to be thrown" in the build output. How can I fix this?

import net.sf.image4j.codec.ico.ICODecoder;

import java.awt.image.BufferedImage;
import java.io.File;
import java.util.List;

public class GUI {
    public GUI() {
        List<BufferedImage> imageList = ICODecoder.read(new File("path (it's  a proper, valid file path in the actual code)"));
    }
    public static void main(String[] args) {
        new GUI();
    }
}

image4j is downloaded from the official site and added as a dependency.

Mark Rotteveel
  • 100,966
  • 191
  • 140
  • 197
  • Welcome! https://stackoverflow.com/questions/908672/why-do-i-get-exception-must-be-caught-or-declared-to-be-thrown-when-i-try-to should answer your question - if not, please [edit] your question to elaborate. In short - you need to either catch the exception and do something about it, or mark your constructor as `throws IOException` and make the caller of the constructor do something about it. – nanofarad Aug 22 '23 at 15:23
  • @nanofarad I can't seem to find the answer to this issue in that question (by that I mean I don't know how to prevent this exception) – Anonymous2840938028 Aug 22 '23 at 15:26
  • Sorry, I pasted the wrong link - please try https://stackoverflow.com/q/72751842/1424875 for a longer explanation (compared to the tl;dr in my previous comment) – nanofarad Aug 22 '23 at 15:33
  • Thanks, that was really helpful, before this I submitted an edit for review and reopening, is there any way I can cancel that now? (I'm new to Stack overflow) – Anonymous2840938028 Aug 22 '23 at 15:54
  • I don't think there's a need to cancel it (and I'm not sure how to cancel it either); worst case nothing will be done when a reviewer hits it. Thanks and welcome again! – nanofarad Aug 22 '23 at 16:00

0 Answers0