Java jar File error message Exception in thread "AWT-EventQueue-0"

759 views Asked by At

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.

0

There are 0 answers