简体   繁体   English

导出后的Eclipse错误

[英]Eclipse Error After Exporting

I updated my project's code, and re-export it using Eclipse, and I ran it in Eclipse, no errors. 我更新了项目的代码,并使用Eclipse重新导出了代码,然后在Eclipse中运行了它,没有错误。 But when I exported it as a Executable Jar File, "javaw.exe" shows up in task manager for a second then disappears, so I decided to start it using command prompt, and I got this error: http://imgur.com/4L2wcSC 但是当我将其导出为可执行Jar文件时,“ javaw.exe”在任务管理器中显示了一秒钟,然后消失了,所以我决定使用命令提示符启动它,但出现了此错误: http : //imgur.com / 4L2wcSC

Whats wrong? 怎么了?

Thanks. 谢谢。

From the looks of it, the exception occurs when you try to load the image. 从外观上看,当您尝试加载图像时会发生异常。 I'm guessing the image is in the jar but you are using the constructor that takes the string filename. 我猜图像在jar中,但是您正在使用采用字符串文件名的构造函数。 Since that file is in the jar, you cannot access it that way. 由于该文件在jar中,因此您无法以这种方式访问​​它。 Instead use getResource which returns a URL. 而是使用getResource返回URL。

You could do something like: 您可以执行以下操作:

URL url = Thread.currentThread().getContextClassLoader().getResource('/path/to/your/image');
new ImageIcon(url);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM