Cloxygen Posted April 3, 2018 Posted April 3, 2018 Last time I touched this script there was no trouble, that was like 6 months ago. For some reason trying to load local resources returns null no matter what I try. (I've read through the forums and practically every google result, nothing has worked so far.) private Image bg; private Image bankPaintOn; private Image bankPaintOff; private Image startButtonimg; private Image cursor; @Override public void onStart() { bg = getImage("images/Background.png"); bankPaintOn = getImage("images/banking_On.png"); bankPaintOff = getImage("images/banking_Off.png"); startButtonimg = getImage("images/Start.png"); cursor = getImage("images/Cursor.png"); } private Image getImage(String path) { Image img; try{ img = ImageIO.read(this.getClass().getResourceAsStream(path)); return img; } catch(IOException e){ log(e); return null; } } [ERROR][Bot #1][04/03 07:46:26 PM]: Error in script onStart(): java.lang.IllegalArgumentException: input == null! at javax.imageio.ImageIO.read(Unknown Source) at Main.getImage(Main.java:604) at Main.onStart(Main.java:208) at org.osbot.rs07.event.ScriptExecutor.IiIiIiiiiIII(em:105) at org.osbot.rs07.event.ScriptExecutor.start(em:234) at org.osbot.ub.run(bx:36) at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source) at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source) at java.lang.Thread.run(Unknown Source)
battleguard Posted April 4, 2018 Posted April 4, 2018 (edited) embeded resources will not work in osbot you will have to download the images from the web or you can put them in your osbot data folder. Here is some example code of where I try to load a file from the osbot data directory and if not found I download it from the web and create the cache https://github.com/battleguard/easyalch/blob/master/src/script/services/PriceLoader.java#L100 Here someones example snippet of a file utility class Edited April 4, 2018 by battleguard
Cloxygen Posted April 4, 2018 Author Posted April 4, 2018 (edited) 17 hours ago, battleguard said: embeded resources will not work in osbot you will have to download the images from the web or you can put them in your osbot data folder. Here is some example code of where I try to load a file from the osbot data directory and if not found I download it from the web and create the cache https://github.com/battleguard/easyalch/blob/master/src/script/services/PriceLoader.java#L100 Here someones example snippet of a file utility class Thanks for the reply. Is this new that local resources don't work? Edited April 4, 2018 by Cloxygen
liverare Posted April 4, 2018 Posted April 4, 2018 (edited) Resources works for the SDN, but not for local scripts. To get around this, you'll need two separate pieces of interchangeable code. When you're ready to publish your script, make sure to have the script load assets from the resource folder. Otherwise, have the script load the resource from the data folder. For example: /** * Attempt to load sprites from resource folder. * * @param dir * - (e.g. "/resources/sprites/record-blue.png") * @return new {@link ImageIcon} instance */ private static ImageIcon loadImageFromResource(String dir) { ImageIcon imageIcon = null; try { imageIcon = new ImageIcon(ImageIO.read(MacroRecorder.class.getResourceAsStream(dir))); } catch (IOException e) { //Attempt to print to GLOBAL_LOGGER Logger.GLOBAL_LOGGER.error(e); } return imageIcon; } /*private static ImageIcon loadImageFromResource(String dir) { ImageIcon imageIcon = null; try { imageIcon = new ImageIcon( ImageIO.read(new File(String.format("%s/OSBot/Data/%s", System.getProperty("user.home"), dir)))); } catch (IOException e) { Logger.GLOBAL_LOGGER.error(e); } return imageIcon; }*/ Edited April 4, 2018 by liverare
Alek Posted April 4, 2018 Posted April 4, 2018 1 hour ago, liverare said: Resources works for the SDN, but not for local scripts. To get around this, you'll need two separate pieces of interchangeable code. When you're ready to publish your script, make sure to have the script load assets from the resource folder. Otherwise, have the script load the resource from the data folder. For example: /** * Attempt to load sprites from resource folder. * * @param dir * - (e.g. "/resources/sprites/record-blue.png") * @return new {@link ImageIcon} instance */ private static ImageIcon loadImageFromResource(String dir) { ImageIcon imageIcon = null; try { imageIcon = new ImageIcon(ImageIO.read(MacroRecorder.class.getResourceAsStream(dir))); } catch (IOException e) { //Attempt to print to GLOBAL_LOGGER Logger.GLOBAL_LOGGER.error(e); } return imageIcon; } /*private static ImageIcon loadImageFromResource(String dir) { ImageIcon imageIcon = null; try { imageIcon = new ImageIcon( ImageIO.read(new File(String.format("%s/OSBot/Data/%s", System.getProperty("user.home"), dir)))); } catch (IOException e) { Logger.GLOBAL_LOGGER.error(e); } return imageIcon; }*/ Use getDirectoryData() from Script 1