0

I get the following error when I try to run my jar file from a Batch file and CMD manually (The batch file is just set to run the jar and record any output to a text file, and open it after).

Exception in thread "main" java.lang.IllegalArgumentException: input == null! at javax.imageio.ImageIO.read(Unknown Source) at com.github.bewd.project.main.Main.<init>(Main.java:37) at com.github.bewd.project.main.Main.main(Main.java:76)

However running from Netbeans, it works perfectly; JFrame and all. I'm not sure if it's something wrong with my classpath (which I don't think is likely) or something in my code that's affecting it, here's the code:

import java.awt.Graphics;
import java.awt.image.BufferedImage;
import java.io.IOException;
import java.math.*;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Map;
import java.util.Random;
import java.util.Scanner;
import java.util.logging.Logger;
import javax.imageio.ImageIO;
import javax.swing.JFrame;
import javax.swing.JPanel;

public class Main extends JPanel{

   public static final String imgPathCard = "./img/cards/";
   public static final String imgPathLogo = "./img/logos/";
   public static final String fontPath = "./fonts/";
   private static final int appVersionMajor = 0;
   private static final double appVersionMinor = 1.3;
   private static final String appName = "Name";
   private static final String appStage = "A";
   private static final String versionString = appName + " (" + appVersionMajor + "." + appVersionMinor + " " + appStage + ")";
   private BufferedImage sdk1, sdk2, sdk3, sdk4, sdk5, sdk6, sdk7, sdk8, sdk9, sdk10, bc;

   public Main() {

   try {
        sdk1 = ImageIO.read(getClass().getResourceAsStream(imgPathCard + "sdk001.png"));
        sdk2 = ImageIO.read(getClass().getResourceAsStream(imgPathCard + "sdk002.png"));
        sdk3 = ImageIO.read(getClass().getResourceAsStream(imgPathCard + "sdk003.png"));
        sdk4 = ImageIO.read(getClass().getResourceAsStream(imgPathCard + "sdk004.png"));
        sdk5 = ImageIO.read(getClass().getResourceAsStream(imgPathCard + "sdk005.png"));
    } 
    catch (IOException e) {
        Logger LogErr = Logger.getLogger(Main.class.getName());
        System.err.println(appName + " " + "Caught IOException: " + e.getMessage());
    }

}

@Override
protected void paintComponent(Graphics g) {
    super.paintComponent(g);
    g.drawImage(sdk1, 0, 0, Card.cardWidth / 5, Card.cardHeight / 5, null);
    g.drawImage(sdk2, Card.cardLong, 0, Card.cardWidth / 5, Card.cardHeight / 5, null);
    g.drawImage(sdk3, Card.cardLong * 2, 0, Card.cardWidth / 5, Card.cardHeight / 5, null);
    g.drawImage(sdk4, Card.cardLong * 3, 0, Card.cardWidth / 5, Card.cardHeight / 5, null);
    g.drawImage(sdk5, Card.cardLong * 4, 0, Card.cardWidth / 5, Card.cardHeight / 5, null);
}

public static void main(String[] args) {

        Main main = new Main();
        JFrame frame = new JFrame(versionString);
        frame.add(main);
        frame.setSize(1020, 680);
        frame.setVisible(true);
        frame.setResizable(false);
        frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        frame.setExtendedState(JFrame.MAXIMIZED_BOTH);
    }
}
BlueEyesWhiteDragon
  • 427
  • 1
  • 6
  • 20
  • Where is `img` located in your file structure? – Paul Samsotha Jun 07 '14 at 11:48
  • package: `com.github.bewd.project.main` This package has three subpackages: `img`, `font`, `snapshots` So: `com.github.bewd.project.main.img`; – BlueEyesWhiteDragon Jun 07 '14 at 11:49
  • And where is the calling class located? – Paul Samsotha Jun 07 '14 at 11:52
  • Well, the images are supposed to read in `Main()`... and then painted onto the `JFrame` at `paintComponent(Graphics g)`. – BlueEyesWhiteDragon Jun 07 '14 at 11:53
  • 1
    I would just create a separate package from the root of the class path `src/resources/img/cards` then your path prefix just use `"/resources/img/cards/"` – Paul Samsotha Jun 07 '14 at 11:54
  • Would `public static final String imgPathCard = "./resources/img/cards/";` be accurate? or would I just use `"/resources/img/cards/",` or even put the whole package directory in? – BlueEyesWhiteDragon Jun 07 '14 at 12:02
  • Forget the `.` in the front. You don't need it. The `/` already brings you to the root of the class path – Paul Samsotha Jun 07 '14 at 12:03
  • Now from Netbeans I get: `Exception in thread "main" java.lang.IllegalArgumentException: input == null! at javax.imageio.ImageIO.read(ImageIO.java:1348) at com.github.bewd.project.main.Main.(Main.java:37) at com.github.bewd.project.main.Main.main(Main.java:76) Java Result: 1` – BlueEyesWhiteDragon Jun 07 '14 at 12:04
  • Read some of my post [HERE](http://stackoverflow.com/questions/23506089/how-to-add-txt-file-to-a-jtextarea-and-where-to-place-my-txt-file/23506266#23506266) and [HERE](http://stackoverflow.com/questions/22744920/how-to-retrieve-image-from-project-folder/22746825#22746825) that might help you. – Braj Jun 07 '14 at 12:08
  • @Braj, I don't understand what you are trying to tell me. (<.<) (>.>) But I thank you for the help. – BlueEyesWhiteDragon Jun 07 '14 at 12:11
  • Different situation. But I've solved it. – BlueEyesWhiteDragon Jun 09 '14 at 16:44

0 Answers0