Spills Posted June 25, 2022 Share Posted June 25, 2022 For some reason the BufferedImage that I want to paint is constantly returning null even through it's not throwing any exceptions when I read it. public class SpillsFisher extends Script { private BufferedImage background; public final void onStart() throws InterruptedException { try { background = ImageIO.read(getScriptResourceAsStream("resources/background.png")); log("No exceptions"); } catch (IOException e) { log(e.fillInStackTrace()); } } public void onPaint(Graphics2D g) { if(background != null){ g.drawImage(background, null, 10, 10); log("Not null"); } else { log("is null"); <-- it's always returning null here } } Structure within IDE Structure within 7zip (It has the resources folder and the image inside) I was using this post as a point of reference: I've also tried: background = ImageIO.read(SpillsFisher.class.getResourceAsStream("/resources/background.png")); From Having the same issue either way, any ideas? Quote Link to comment Share on other sites More sharing options...
Khaleesi Posted June 26, 2022 Share Posted June 26, 2022 What I do is fetch the image from an url like imgur Save it in the Osbot/data folder and load it in next time, if it's not there download it again. public static BufferedImage getImage(Script script, String url) { try { return ImageIO.read(new URL(url)); } catch (IOException e) { script.log("Failed to load image with url: " + url); } return null; } 1 Quote Link to comment Share on other sites More sharing options...
Spills Posted June 26, 2022 Author Share Posted June 26, 2022 3 hours ago, Khaleesi said: What I do is fetch the image from an url like imgur Save it in the Osbot/data folder and load it in next time, if it's not there download it again. public static BufferedImage getImage(Script script, String url) { try { return ImageIO.read(new URL(url)); } catch (IOException e) { script.log("Failed to load image with url: " + url); } return null; } Ahah! I appreciate the response, funnily enough I was thinking about doing it this way, thank you! 1 Quote Link to comment Share on other sites More sharing options...