0

I'm not sure why I'm getting the npe, I can read other files in a directory next to src/main/resources.

Its a maven based project run from eclipse.

any ideas?

Java ..

StringBuilder sb = new StringBuilder();
try {

    InputStream is = ShaderControl.class.getResourceAsStream("fragmentShader.txt");
    BufferedReader br = new BufferedReader(new InputStreamReader(is, "UTF-8"));

    String line;
    while ((line = br.readLine()) != null) {

        sb.append(line);
        sb.append('\n');
    }
    is.close();

} catch (Exception e) {
    e.printStackTrace();
}
System.out.println("Shader is " + sb.toString());

Console output ..

java.lang.NullPointerException
    at java.io.Reader.<init>(Reader.java:90)
    at java.io.InputStreamReader.<init>(InputStreamReader.java:119)
    at justc0de.engine.tools.ShaderControl.loadShader(ShaderControl.java:36)
    at justc0de.engine.ui.GameRenderer.init(GameRenderer.java:157)
    at jogamp.opengl.GLDrawableHelper.init(GLDrawableHelper.java:640)
    at jogamp.opengl.GLDrawableHelper.init(GLDrawableHelper.java:662)
    at javax.media.opengl.awt.GLCanvas$9.run(GLCanvas.java:1366)
    at jogamp.opengl.GLDrawableHelper.invokeGLImpl(GLDrawableHelper.java:1275)
    at jogamp.opengl.GLDrawableHelper.invokeGL(GLDrawableHelper.java:1131)
    at javax.media.opengl.awt.GLCanvas$11.run(GLCanvas.java:1394)
    at java.awt.event.InvocationEvent.dispatch(InvocationEvent.java:314)
    at java.awt.EventQueue.dispatchEventImpl(EventQueue.java:750)
    at java.awt.EventQueue.access$300(EventQueue.java:115)
    at java.awt.EventQueue$3.run(EventQueue.java:711)
    at java.awt.EventQueue$3.run(EventQueue.java:709)
    at java.security.AccessController.doPrivileged(AccessController.java:311)
    at java.security.ProtectionDomain$1.doIntersectionPrivilege(ProtectionDomain.java:88)
    at java.awt.EventQueue.dispatchEvent(EventQueue.java:720)
    at java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:254)
    at java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:173)
    at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:162)
    at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:158)
    at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:150)
    at java.awt.EventDispatchThread.run(EventDispatchThread.java:103)
Shader is 
Program link error: 

Directory listing ..

rob@work:~/git/justc0de$ ls src/main/resources/*.txt
src/main/resources/fragmentShader.txt  src/main/resources/vertexShader.txt
1
  • Could there be a trailing space in the filename on disk? Are you sure the source posted is what you're executing? Is the resources dir in your classpath? Commented Mar 31, 2015 at 23:22

1 Answer 1

1

Discovered it should have been ..

InputStream is = ShaderControl.class.getResourceAsStream("/fragmentShader.txt");
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.