SodiumFRP / sodium

Sodium - Functional Reactive Programming (FRP) Library for multiple languages
http://sodium.nz/
Other
851 stars 140 forks source link

Book -> petrol pump example -> reading resources #100

Closed kostadinnm closed 8 years ago

kostadinnm commented 8 years ago

Hello,

I am trying to follow the book and I got up to chapter 4 - the petrol pump example. However, I have difficulty running the example. The thing is, although I focus on the logic as you advice, I am writing all of the code(except the lib itself, of course) by hand. It seems we're using the same IDE(Intellij Idea), but I hadn't even opened the project you provide(I followed the advice to install sodium as a maven package). I've written the first three versions of the pump - LifeCyclePump, AccumulatePulsesPump and ShowDollarsPump. When I try to run it, I get an exception when it tries to read the images and sounds - "File not found, etc". I need to continue and I need a working example, so I decided not to go too deep into 'Java & resources'. And, because we have different project structure, I think I need to move the image and sound files a couple of folders.

So I tried copying the two resource folders("images" and "sounds") one folder up and down, but it still gives me the same exception. The path(a call to .getPath() on the URL object) is a String similar to this: <mymachine>/<projects>/FRP_FuelPump/../images/petrol-pump-front.png It looks like the two dots("..") are disturbing the execution. Without them(I fix the value through debugging)the problematic row(PetrolPump.java -> line 95): background = ImageIO.read(new URL(rootURL, "../images/petrol-pump-front.png")); passes like charm and no exception is thrown. I couldn't find anywhere on the Internet, how in Java relative paths are constructed with the double dot(s) syntax/notion?! Also, this is very rare(PetrolPump.java -> line 459): URL rootURL = new URL("file:."); At first, I thought it could be separator issue, but replacing the '/' with File.separator runs exactly the same. Could you help me out with this?! As you might have already guessed, I am new to Java as well and this got annoyed as I am unable to continue with the important stuff Sodium provides :)

With regards, Kostadin

kostadinnm commented 8 years ago

Sorry, guys - my mistake. I misplaced the two folders. What tricked me were the double dots("..") shown in the debugger. I think I should've been using getCanonicalPath() or sth to get better understanding of what's happening.

For those who are writing it all by themselves(and are using the generic maven template/archetype, where you have src/main/java), the "images" and "sounds" folders should be placed within their projects folder(i.e. along with your other projects, and NOT in the Fuel Pump project dir).

Still, I might make up a better solution and if it ok, I may present it :)

Cheers, Kostadin

the-real-blackh commented 8 years ago

I'm glad you figured it out! I put those directories in odd places in order to share them with other languages. I'm happy to change it if you have a better solution.