简体   繁体   English

Eclipse IDE项目目录结构帮助[Java]

[英]Eclipse IDE project directory structure help [Java]

I have been learning Java and have had no problem with projects in which multiple .java files were in the same Default Package. 我一直在学习Java,并且对于多个.java文件位于同一默认包中的项目没有任何问题。 I am now trying to separate code and create folders for images, but everything I have tried has failed. 我现在试图分离代码并为图像创建文件夹,但是我尝试的所有操作均失败了。

How do I properly add folders for images and other classes, and properly set the path to it? 如何正确添加图像和其他类的文件夹,并正确设置其路径? All paths should be relative to the project, I know that much ;_; 所有路径都应与项目相关,我知道很多;

Here's a link to a picture of my IDE and error message from program output: 这是我的IDE图片和程序输出错误消息的链接:

http://img262.imageshack.us/img262/8415/directory.png http://img262.imageshack.us/img262/8415/directory.png

Thanks!! 谢谢!!

First off, your Java code itself should go into a package, not the default package. 首先,您的Java代码本身应该放入一个包中,而不是默认包中。 Next, you may be able to refer to the image file by prepending src/ to your path: 接下来,您可以通过在路径前面加上src /来引用图像文件:

"src/Textures/Crate.png" “ src / Textures / Crate.png”

But better would be to get the image as a resource, not as a file using the Class#getResourceAsStream. 但是更好的方法是使用Class#getResourceAsStream将图像作为资源而不是文件。

使用鼠标将Textures文件夹拖到LWJGL 6项目文件夹。

尝试使用src/Textures/Crate.png作为FileInputStream构造函数的路径。

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

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