This is a question that was asked 100 times on this site, but I looked at all of them, and although all of them were resolved, none of the solutions worked for me.
This is what my code looks like:
public Button1(Client client, String imgName) { this.client = client; try { this.icon = ImageIO.read(this.getClass().getResourceAsStream("/resources/" + imgName)); } catch (IOException e) { e.printStackTrace(); }
When you run the code, the following error occurs:
Exception in thread "main" java.lang.IllegalArgumentException: input == null! at javax.imageio.ImageIO.read(Unknown Source)
The string imgName is passed to the constructor from the child class and is the name of the image (for example, image.png). I also made sure that my resources folder is in the root of the project folder and is included as the source folder in the eclipse project. I also made sure that System.getProperty("user.dir") points to the correct location. I also tried using getResource () instead of getResourceAsStream (), but it still does not work.
java bufferedimage javax.imageio
tyler
source share