我正在编写一个程序并尝试将其导出并将其发送给某人。当我在 Eclipse 中运行该程序时,它运行良好。但是,当我将它导出为 Runnable JAR 文件并双击它时,它会退出并告诉我检查控制台。
这是堆栈跟踪:
javax.imageio.IIOException: Can't read input file!
at javax.imageio.ImageIO.read(ImageIO.java:1275)
at me.pogostick29.audiorpg.util.PrereleaseChecker.run(PrereleaseChecker.java:29)
at me.pogostick29.audiorpg.AudioRPG.main(AudioRPG.java:30)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:597)
at org.eclipse.jdt.internal.jarinjarloader.JarRsrcLoader.main(JarRsrcLoader.java:58)
javax.imageio.IIOException: Can't read input file!
at javax.imageio.ImageIO.read(ImageIO.java:1275)
at me.pogostick29.audiorpg.window.Window.<init>(Window.java:62)
at me.pogostick29.audiorpg.window.WindowManager.setup(WindowManager.java:16)
at me.pogostick29.audiorpg.AudioRPG.main(AudioRPG.java:32)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:597)
at org.eclipse.jdt.internal.jarinjarloader.JarRsrcLoader.main(JarRsrcLoader.java:58)
我认为它没有正确导出图像。这是我访问图像的方式:
BufferedImage myPicture = null;
try { myPicture = ImageIO.read(new File("images/audiorpglogo.png")); }
catch (Exception e) { e.printStackTrace(); }
logo = new JLabel(new ImageIcon(myPicture));
另外,当我尝试
myPicture = ImageIO.read(Window.class.getResource("/images/audiorpglogo.png"));
即使在 Eclipse 中运行,我也会得到堆栈跟踪:
java.lang.IllegalArgumentException: input == null!
at javax.imageio.ImageIO.read(ImageIO.java:1362)
at me.pogostick29.audiorpg.window.Window.<init>(Window.java:70)
at me.pogostick29.audiorpg.window.WindowManager.setup(WindowManager.java:16)
at me.pogostick29.audiorpg.AudioRPG.main(AudioRPG.java:29)