Error Loading Shader in Android Studio

Hello,

My code snippet is below.

First off just in case it is relevant, I moved my .glsl file to the main res folder to get around an error with having path separators in the file name.

It seems to accept that now but throws the following error now and I can’t figure out what the issue is, Any help would be greatly appreciated.

ERROR:

2019-09-20 11:21:56.438 31984-31984/? I/.processigntes: Late-enabling -Xcheck:jni
2019-09-20 11:21:56.458 31984-31984/? E/.processigntes: Unknown bits set in runtime_flags: 0x8000
2019-09-20 11:21:56.646 31984-31984/? W/.processigntes: Accessing hidden method Landroid/view/View;->computeFitSystemWindows(Landroid/graphics/Rect;Landroid/graphics/Rect;)Z (greylist, reflection, allowed)
2019-09-20 11:21:56.647 31984-31984/? W/.processigntes: Accessing hidden method Landroid/view/ViewGroup;->makeOptionalFitsSystemWindows()V (greylist, reflection, allowed)
2019-09-20 11:21:56.768 31984-32020/? I/Adreno: QUALCOMM build : bc00834, I609ab310b2
Build Date : 04/11/19
OpenGL ES Shader Compiler Version: EV031.26.07.00
Local Branch :
Remote Branch :
Remote Branch :
Reconstruct Branch :
2019-09-20 11:21:56.768 31984-32020/? I/Adreno: Build Config : S L 8.0.6 AArch64
2019-09-20 11:21:56.771 31984-32020/? I/Adreno: PFP: 0x005ff110, ME: 0x005ff066
2019-09-20 11:21:56.785 31984-32023/? W/Gralloc3: mapper 3.x is not supported
2019-09-20 11:21:56.832 31984-32023/? E/AndroidRuntime: FATAL EXCEPTION: GLThread 33821
Process: com.example.processigntest, PID: 31984
java.lang.NullPointerException: Attempt to invoke virtual method ‘boolean processing.opengl.PShader.isPolyShader()’ on a null object reference
at processing.opengl.PGraphicsOpenGL.shader(PGraphicsOpenGL.java:7257)
at processing.core.PApplet.shader(PApplet.java:8381)
at com.example.processigntest.Sketch.draw(Sketch.java:49)
at processing.core.PApplet.handleDraw(PApplet.java:1855)
at processing.opengl.PSurfaceGLES$RendererGLES.onDrawFrame(PSurfaceGLES.java:264)
at android.opengl.GLSurfaceView$GLThread.guardedRun(GLSurfaceView.java:1573)
at android.opengl.GLSurfaceView$GLThread.run(GLSurfaceView.java:1272)

CODE:

import processing.core.PApplet;
import processing.core.PImage;
import processing.opengl.PShader;

public class Sketch extends PApplet {

PShader detect;
PImage test1,test2;

public void settings() {
    size(1920, 1080, P3D);

}

public void setup() {

loadShader(“detect.glsl”);
}
public void draw() {

shader(detect);
test1 = loadImage("/storage/emulated/0/DCIM/Testimg/pic 10.jpg");

}

}

Welcome to the forums! In the future, please use the </> button to format your code snippets.

While you declare detect up top, you never actually assign it with loadShader()!
Check out the loadShader() example.

1 Like

add use of

test1 = loadImage("/storage/emulated/0/DCIM/Testimg/pic 10.jpg");

inside of draw
should be avoided,
please better move to setup().


? and how about show it with

image(test1,x,y);

in draw()?