.getResourceAsStream()

Im having problems with reading form files using getResourceAsStream(). I understadnd that the problem is the address i give it, so it get nullpointer all the time, but i dont understand why.

i give it C:/Users/Marko/git/Over-The-Galaxy/src/shader.frag i have tried everything in between and i still get the error.

[quote]java.lang.NullPointerException
at java.io.Reader.(Unknown Source)
at java.io.InputStreamReader.(Unknown Source)
at test.OBJloader.ShaderProgram.readFromFile(ShaderProgram.java:82)
at test.OBJloader.ShaderProgram.attachFragmentShader(ShaderProgram.java:35)
at test.OBJloader.Model.prepareVBO(Model.java:300)
at test.OBJloader.OBJLoader.loadModel(OBJLoader.java:71)
at controller.Controller.(Controller.java:52)
at controller.Controller.main(Controller.java:110)
[/quote]
What kind of address does it want?

BufferedReader reader = new BufferedReader(new InputStreamReader(
					ShaderProgram.class.getClassLoader()
					.getResourceAsStream(name)));

Create a folder called “res” in your main project folder. Near the src folder.
I hope you’re using eclipse, I don’t know about other IDEs.
Right click project, Build Path -> Configure Build Path -> Libraries -> Add Class Folder -> (Now select res folder)
Now when you do class.getResource();, you need to specify a path FROM the res folder. So, in your case, it might be something like “/shaders/shader.frag”, assuming you created a folder in your res folder called “shaders” and put your “shader.frag” in that folder.

Ty, this works :smiley: