Can I use URL when executing java code in eclipse

我们两清 提交于 2019-12-25 01:47:07

问题


My simple safari simulator uses some png images to display output. I originally loaded the images using:

lionImage = Toolkit.getDefaultToolkit().getImage("images/lion.png");

This worked like a charm until I tried to export my program as a jar file. A quick search found the solution, so now I use:

lionImage = Toolkit.getDefaultToolkit().getImage(
                GameReserve.class.getResource("images/lion.png"));

...which works fine in the jar but won't run in eclipse!

So my question is do I really need two different versions of my code (one to run when I am developing the project and another for export to jar)? Or can they be combined to work in both environments?

来源:https://stackoverflow.com/questions/28498668/can-i-use-url-when-executing-java-code-in-eclipse

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!