当我尝试从批处理文件和CMD手动运行我的jar文件时,我收到以下错误(批处理文件只是设置为运行jar并将任何输出记录到文本文件中,然后打开它)。< / p>
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)
然而从Netbeans运行,它运作完美; JFrame和所有。我不确定我的类路径是否有问题(我认为不太可能)或我的代码中的某些内容会影响它,这里是代码:
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);
}
}