Results 1 to 6 of 6
Thread: spriteSheet wont load?
- 01-23-2012, 03:33 AM #1
spriteSheet wont load?
Ok,so i finally found out how to get a sprite sheet.But now,i get this error:
Window.java:Java Code:Exception in thread "main" java.lang.IllegalArgumentException: input == null! at javax.imageio.ImageIO.read(Unknown Source) at Src.SpriteSheet.BufferedImageLoader.loadImage(BufferedImageLoader.java:12) at Window.init(Window.java:34) at Window.<init>(Window.java:27) at Window.main(Window.java:57)
SpriteSheet.javaJava Code:import java.awt.Graphics; import java.awt.image.BufferedImage; import java.io.File; import java.io.IOException; import java.util.logging.Level; import java.util.logging.Logger; import javax.swing.JFrame; import java.awt.*; import Src.SpriteSheet.*; import Src.SpriteSheet.BufferedImageLoader; import Src.SpriteSheet.SpriteSheet; public class Window extends JFrame { BufferedImage sprite; private Image dbImage; // Double buffer image private Graphics dbg; // double buffer graphics public Window(){ setSize(800, 600); setVisible(true); setResizable(false); setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); setLocationRelativeTo(null); init(); } private void init(){ BufferedImageLoader loader = new BufferedImageLoader(); BufferedImage spriteSheet = null; try{ spriteSheet = loader.loadImage("C:\\Game\\spritesheet.png"); } catch (IOException ex) { Logger.getLogger(Window.class.getName()).log(Level.SEVERE, null, ex); } SpriteSheet ss = new SpriteSheet(spriteSheet); sprite = ss.grabSprite(0, 16, 16, 16); } @Override public void paint(Graphics g){ dbImage = createImage(getWidth(), getHeight()); dbg = dbImage.getGraphics(); paintComponent(dbg); g.drawImage(dbImage, 0, 0, this); } public void paintComponent(Graphics graphics) { } public static void main(String[] args) { new Window(); } }
BufferedImageLoader.javaJava Code:package Src.SpriteSheet; import java.awt.image.BufferedImage; public class SpriteSheet { public BufferedImage spriteSheet; public SpriteSheet(BufferedImage ss){ this.spriteSheet = ss; } public BufferedImage grabSprite(int x, int y, int width, int height){ BufferedImage sprite = spriteSheet.getSubimage(x, y, width, height); return sprite; } }
any help?Java Code:package Src.SpriteSheet; import java.awt.image.BufferedImage; import java.io.IOException; import java.net.URL; import javax.imageio.ImageIO; public class BufferedImageLoader { public BufferedImage loadImage(String pathRelativeToThis) throws IOException { URL url = this.getClass().getResource(pathRelativeToThis); BufferedImage img = ImageIO.read(url); return img; } }
- 01-23-2012, 01:20 PM #2
Re: spriteSheet wont load?
The error says that the input to a method is null. Go to line 12 in BufferedImageLoader and check that the value of the argument to the method called there is not null.Exception in thread "main" java.lang.IllegalArgumentException: input == null!
at javax.imageio.ImageIO.read(Unknown Source)
at Src.SpriteSheet.BufferedImageLoader.loadImage(Buff eredImageLoader.java:12)
What is the value of the path you are passing the getResource? Is it on the classpath?
- 01-24-2012, 01:13 AM #3
Re: spriteSheet wont load?
Error right there...Can't see whats wrong.Java Code:public BufferedImage loadImage(String Path) throws IOException { URL randomStuff = this.getClass().getResource(Path); BufferedImage img = ImageIO.read(randomStuff); return img; }
- 01-24-2012, 01:17 AM #4
Re: spriteSheet wont load?
The error occurs at run time. What is the value of the path variable (lowercase first letter for variables)?
Is it a valid parameter for the getResource() method?
What is the value of randomStuff after the getResource() method is called?
Add some printlns to print out the value of the variables to see what is wrong..Can't see whats wrong.
- 01-26-2012, 07:32 AM #5
Re: spriteSheet wont load?
Sprite Sheets - #1 - General Java Game Development Tutorials - YouTube
Heres the tutorial.I println but i get "null".
- 01-26-2012, 12:52 PM #6
Similar Threads
-
this wont run again and again?? why?
By vibaviattigala in forum New To JavaReplies: 2Last Post: 07-16-2011, 08:30 AM -
Java wont load
By doorpro in forum New To JavaReplies: 12Last Post: 07-10-2011, 07:02 PM -
.jar wont run?
By stevenpalomino in forum New To JavaReplies: 1Last Post: 06-30-2011, 10:11 AM -
save will work but load wont?!?!
By Sticks_ll in forum New To JavaReplies: 1Last Post: 06-12-2008, 04:19 AM


LinkBack URL
About LinkBacks
Reply With Quote

Bookmarks