Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>The error was the first line of "saveResource()":</p> <pre><code>InputStream stream = this.getClass().getResourceAsStream(fromFile); </code></pre> <p>Here, "stream" was always null. Here is the way to solve this (using Eclipse):</p> <ol> <li><p>Create a new <strong>package</strong> in <strong>src</strong> (let's call it <em>resources</em>).</p></li> <li><p>Create a new <strong>folder</strong> in your <strong>package</strong> (let's call it <em>myPictures</em>)</p></li> <li><p>Create more folders if you want. I'll create a new folder inside <em>myPictures</em> and I'll call it <em>partyPictures</em></p></li> <li><p>Choose one of your folders and put the images (or whatever) inside. I'll have an image called <em>imageName.jpg</em> inside <em>partyPictures</em></p></li> <li><p>Then, go to the "Navigator", find your Proyect, and you will see that there is a folder called <em>bin</em>. Inside, you should see your packages organised in folders. </p></li> <li><p>Look for the folder inside <em>bin</em> that has the name of the package you created before (I'll have a folder called <em>resources</em>). Inside the folder you'll see a tree-view of the folders inside the package (the ones you created before).</p></li> <li><p>Look for your files. (I'll look for <em>resources/myPictures/partyPictures/imageName.jpg</em>)</p></li> <li><p>If it doesn't exist, <strong>InputStream stream = this.getClass().getResourceAsStream(fromFile);</strong> will always null. To fix this, copy the image (or whatever file) to the folder.</p></li> <li><p>Then use</p> <pre><code>String fromFile = "/resources/myPictures/partyPictures/imageName.jpg"; InputStream stream = this.getClass().getResourceAsStream(fromFile); </code></pre></li> <li><p>Change the String <strong>fromFile</strong> to your file's path, and always start with a <strong>/</strong>. Your code will look like this:</p></li> </ol> <p>String fromFile = "/<strong>packageName</strong>/ <strong>folderName</strong>/ <strong>fileName.extension</strong>";</p> <p>InputStream stream = this.getClass().getResourceAsStream(fromFile);</p> <h1>That should be it!</h1>
 

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