Results 1 to 6 of 6
  1. #1
    chrisall76's Avatar
    chrisall76 is offline Member
    Join Date
    Dec 2011
    Location
    pittsburg
    Posts
    6
    Rep Power
    0

    Unhappy spriteSheet wont load?

    Ok,so i finally found out how to get a sprite sheet.But now,i get this error:
    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)
    Window.java:
    Java 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();
        }
    }
    SpriteSheet.java
    Java 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;
        }
        
    }
    BufferedImageLoader.java
    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;
        }
        
    }
    any help?

  2. #2
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    SW Missouri
    Posts
    17,516
    Rep Power
    25

    Default Re: spriteSheet wont load?

    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)
    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.

    What is the value of the path you are passing the getResource? Is it on the classpath?

  3. #3
    chrisall76's Avatar
    chrisall76 is offline Member
    Join Date
    Dec 2011
    Location
    pittsburg
    Posts
    6
    Rep Power
    0

    Default Re: spriteSheet wont load?

    Java Code:
        public BufferedImage loadImage(String Path) throws IOException {
            URL randomStuff = this.getClass().getResource(Path);
            BufferedImage img = ImageIO.read(randomStuff);
            return img;
        }
    Error right there...Can't see whats wrong.

  4. #4
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    SW Missouri
    Posts
    17,516
    Rep Power
    25

    Default 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?
    .Can't see whats wrong.
    Add some printlns to print out the value of the variables to see what is wrong.

  5. #5
    chrisall76's Avatar
    chrisall76 is offline Member
    Join Date
    Dec 2011
    Location
    pittsburg
    Posts
    6
    Rep Power
    0

    Default Re: spriteSheet wont load?

    Sprite Sheets - #1 - General Java Game Development Tutorials - YouTube
    Heres the tutorial.I println but i get "null".

  6. #6
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    SW Missouri
    Posts
    17,516
    Rep Power
    25

    Default Re: spriteSheet wont load?

    Can you copy and post what is printed on the console?
    What variable is null?

Similar Threads

  1. this wont run again and again?? why?
    By vibaviattigala in forum New To Java
    Replies: 2
    Last Post: 07-16-2011, 08:30 AM
  2. Java wont load
    By doorpro in forum New To Java
    Replies: 12
    Last Post: 07-10-2011, 07:02 PM
  3. .jar wont run?
    By stevenpalomino in forum New To Java
    Replies: 1
    Last Post: 06-30-2011, 10:11 AM
  4. save will work but load wont?!?!
    By Sticks_ll in forum New To Java
    Replies: 1
    Last Post: 06-12-2008, 04:19 AM

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •