This content has been marked as final. Show 6 replies
well the file really does not exist, otherwise it would work. So the problem must lie in what the absolute path of the file is, as you are passing a relative path.
The way I do it is to put the files in the classpath. Then you can load them through the classloader, with ClassLoader.getResourceAsStream(). When you have your resources on the classpath, you can even bundle them with your application in the same jar, and it will work the same on all systems. Or you could put them in a separate jar if you want.
Okay, now I am confused. I took the program onto a flash drive (just took the whole NetBeans project folder and copied it) and moved it to one of the computers in my programming class, where they only had an editor called jEdit (don't know if you've heard of it or not). I compiled it in the shell, planning on asking my teacher for help, but it worked! Now I am still on jEdit, taking the program to the next step, and haven't received any serious errors yet.
Why would it work in the command shell, but not in NetBeans?
did you run it FROM netbeans? In that case the working directory is different. You can manually set the working directory in the project properties, set it to where the files are that you are trying to load.
It says the directory is in the src folder in my project file. I already have everything in that folder. All I did to compile it in the shell was to add the batch file in that same folder.
Plus, I'm not getting any NullPointerExceptions (or any exceptions), so doesn't that mean it can see the file? Just for some reason it isn't assigning it to tileset in NetBeans but it is in the shell?
it is just designed this way, trying to render a null image simply does nothing.
Do the following: create some directory somewhere where you put the files of your application. Choose any directory, but make it one that is not part of the netbeans project. Now in the project properties simply make the working directory (I think you can find it under the run menu option, I don't have netbeans installed here at work) point to your newly created directory.
As an example: you use c:\project\game\data as your working directory. If you run the application and you load a file from 'tiles\tileset.png', then the full path on disc should be c:\project\game\data\tiles\tileset.png.
Perfect. Worked like a charm. Thanks much.