0

I'm trying to learn how to program frames in Java and I ran into a problem. When I create a jar file of my code I come up with a blank screen. My previous jar files don't have the same problem. When I ran the jar file through command prompt I got the following error message:

Exception in thread "AWT-EventQueue-0" java.lang.IllegalArgumentException: input == null!
        at javax.imageio.ImageIO.read(Unknown Source)
        at getResources.getImg(getResources.java:31)
        at MyCanvas.paint(gameLoop.java:99)
        at javax.swing.JComponent.paintChildren(Unknown Source)
        at javax.swing.JComponent.paint(Unknown Source)
        …

Here is the code for the main class and MyCanvas class:

class MyCanvas extends JComponent{

    public void paint(Graphics g){
       getResources get = new getResources();

        BufferedImage titleImg = get.getImg("Title");
        BufferedImage testImg = get.getImage("");
        g.drawImage(titleImg, 0, 0, null);
        g.drawImage(testImg, 0 , 0, null);
    }

}

Here is the code for my "getResources" class:

import java.awt.Graphics;
import javax.swing.JComponent;
import javax.swing.JFrame;
import java.awt.Color;
import java.awt.Dimension;
import javax.swing.JPanel;
import java.awt.*;
import java.awt.event.*;
import java.awt.image.*;
import java.io.*;
import javax.imageio.*;
import javax.swing.*;
import java.awt.Font;
import sun.audio.AudioData;
import sun.audio.AudioPlayer;
import sun.audio.AudioStream;
/**
 * Write a description of class getResources here.
 * 
 * @author (your name) 
 * @version (a version number or a date)
 */
public class getResources{
public void getResources(){

}

public BufferedImage getImg(String path){
    BufferedImage img = null;
    try {                
        img = ImageIO.read(this.getClass().getResource("/Sprites/" + path + ".png"));
   } catch (IOException e) {
        e.printStackTrace();
   }
   return img;
}

public BufferedImage getImage(String path){
    BufferedImage img = null;
    try {                
        img = ImageIO.read(this.getClass().getResource("/Sprites/test.png"));
   } catch (IOException e) {
        e.printStackTrace();
   }
   return img;
}

public AudioStream getSeven(){
    InputStream in;
    AudioStream as = null;
    try{
           in = this.getClass().getResourceAsStream("/Music/seven.wav");
           as = new AudioStream (in);
       }catch(Exception e){
           e.printStackTrace();
       }
    return as;
}
}

I am pretty sure that the error is in the "getImg" method and the way it retrieves images from the source folder. I removed all the lines of codes that had references to that method and the jar file ran just fine. However, the "getImage" class runs just fine in the jar file. Maybe something about passing a string to get the path of the image creates the error? I'd like to know if anyone knows what is causing the error and if I should even be concerned by not being able to run jar files, I do like using them.

llogiq
  • 13,815
  • 8
  • 40
  • 72
Priyank
  • 49
  • 1
  • 2
  • 6
  • input == null ... might be it can't find a file you are linking to. – Stultuske Jun 05 '15 at 07:10
  • The error means, that the required source is not found. Are you sure, you created the directory structure in the right sense. Do have a look at this example, regarding how to [add images to Resource Folder](http://stackoverflow.com/a/9866659/1057230). Hopefully this might be able to help you, in your endeavour. – nIcE cOw Jun 05 '15 at 07:15
  • Share exception stack!!! – Rajesh Jun 05 '15 at 07:18
  • Always include the error *in the question* - and ideally include a *short but complete* program demonstrating the problem. – Jon Skeet Jun 05 '15 at 07:20

0 Answers0