Note that there are some explanatory texts on larger screens.

plurals
  1. POHow do I access a .gif file in a package in the src folder?
    primarykey
    data
    text
    <p>I'm working on a Java program using Eclipse. Right now, I have an src folder that contains 2 packages: memory.views and memory.resources.</p> <p>In the memory.views package, I have my <code>Main.java</code> file. In the memory.resources package, I have my .txt file and .gif file.</p> <p>Within the program, I have no problem accessing (and manipulating) the <code>.txt</code> file by using the path <code>/memory/resources/name.txt</code>. However, when I do the same with the <code>.gif</code> file using the code below, I get no result:</p> <pre><code>ImageIcon icon = new ImageIcon("/memory/resources/name.gif"); </code></pre> <p>There's no error produced. The only effect is that I see no image when the program is running.</p> <p>I've tried also writing the following, but none worked: <br></p> <pre><code>ImageIcon icon = new ImageIcon("/resources/name.gif"); &lt;br&gt; ImageIcon icon = new ImageIcon("name.gif"); </code></pre> <p>Now, just so nobody says that it's the <code>.gif</code> file's fault, I've actually entered in the full Finder path (I'm using a Mac) and that worked perfectly:</p> <pre><code>ImageIcon icon = new ImageIcon("/Users/[...]/src/memory/resources/name.gif"); </code></pre> <p>However, I don't want to do the full path, because if I export the program and run it on another computer, then the non-programming computer won't display the image either.</p> <p>So, right now, I don't even know what the problem is. The .gif file works sometimes, but not when it's accessed via the same path as the .txt file, which works all the time. I tried looking here (<a href="https://stackoverflow.com/questions/11121083/cannot-access-resource-by-using-the-getresources-method">Cannot access resource by using the getResources() method</a>), but it seems like he had a slightly different problem from me.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload