# What's a better way to write my code so I don't keep getting null pointer exceptions

**URL:** <https://discourse.processing.org/t/whats-a-better-way-to-write-my-code-so-i-dont-keep-getting-null-pointer-exceptions/47958>\
**Category:** Libraries\
**Created:** [February 24, 2026, 5:39am UTC](https://discourse.processing.org/t/whats-a-better-way-to-write-my-code-so-i-dont-keep-getting-null-pointer-exceptions/47958 "2026-02-24T05:39:26Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Thorstrum](https://avatars.discourse-cdn.com/v4/letter/t/858c86/32.png) [@Thorstrum](https://discourse.processing.org/u/Thorstrum)\
**Post date:** [February 24, 2026, 5:39am UTC](https://discourse.processing.org/t/whats-a-better-way-to-write-my-code-so-i-dont-keep-getting-null-pointer-exceptions/47958/1 "2026-02-24T05:39:26Z")

</div>

import processing.sound.\*;  
Amplitude amp;  
AudioIn in;  
PImage photo, maskImage;  
void setup() {  
size(600, 400);  
background(255);

// Create an Input stream which is routed into the Amplitude analyzer  
amp = new Amplitude(this);  
in = new AudioIn(this, 0);  
in.start();  
amp.input(in);  
strokeWeight(2);

//background(20,40,70);  
background(0);  
ellipse(width\*.5, height\*.9, 50+amp.analyze()\*1000, 10+amp.analyze()\*800);  
background(20,40,70);

//saveFrame();  
}  
void draw() {  
background(20,40,70);

println(amp.analyze()_1000);  
float a = amp.analyze()500;  
translate(width.5, height_.5);  
fill(60,110,130);  
//stroke(120,220,255);  
beginShape();  
curveVertex(0, 120);  
curveVertex(0, 180);  
curveVertex(-140, 120);  
curveVertex(-255, -95); // top corner  
curveVertex(-250, -100); // top corner  
curveVertex(-185, -50);  
curveVertex(-165, -45);  
curveVertex(-40, -50);  
curveVertex(40, -50);  
curveVertex(165, -45);  
curveVertex(185, -50);  
curveVertex(250, -100); // top corner  
curveVertex(255, -95); // top corner  
curveVertex(140, 120);  
curveVertex(0, 180);  
curveVertex(0, 120);  
endShape();

fill(120,220,255);  
beginShape();  
vertex(-290, -155-a);  
vertex(-290, -105-a);  
vertex(-150, 80-a);//tooth 1  
vertex(-120, 20-a);  
vertex(-75, 105-a);//tooth 2  
vertex(-40, 25-a);  
vertex(0, 110-a);//tooth 3  
vertex(40, 25-a);  
vertex(75, 105-a);//tooth 4  
vertex(120, 20-a);  
vertex(150, 80-a);//tooth 5  
vertex(290, -105-a);  
vertex(290, -155-a);  
endShape();

beginShape();  
vertex(-290, 200+a);  
vertex(-290, -105+a);  
vertex(-150, 80+a);//tooth 1  
vertex(-120, 20+a);  
vertex(-75, 105+a);//tooth 2  
vertex(-40, 25+a);  
vertex(0, 110+a);//tooth 3  
vertex(40, 25+a);  
vertex(75, 105+a);//tooth 4  
vertex(120, 20+a);  
vertex(150, 80+a);//tooth 5  
vertex(290, -105+a);  
vertex(290, 200+a);  
endShape();

saveFrame(“mouth.png”);  
photo = loadImage(“mouth.png”);

background(0);

fill(255);  
stroke(255);  
beginShape();  
curveVertex(0, 120);  
curveVertex(0, 180);  
curveVertex(-140, 120);  
curveVertex(-255, -95); // top corner  
curveVertex(-250, -100); // top corner  
curveVertex(-185, -50);  
curveVertex(-165, -45);  
curveVertex(-40, -50);  
curveVertex(40, -50);  
curveVertex(165, -45);  
curveVertex(185, -50);  
curveVertex(250, -100); // top corner  
curveVertex(255, -95); // top corner  
curveVertex(140, 120);  
curveVertex(0, 180);  
curveVertex(0, 120);  
endShape();

saveFrame(“mask.png”);  
maskImage = loadImage(“mask.png”);

background(0,0,50);  
translate(-width\*.5, -height\*.5);

photo.mask(maskImage);  
image(photo, 0, 0);  
}

I’m currently constantly saving two photos every time draw runs, if someone knows how to just take what’s on screen and load that as an image without having to save it as a file i think that would fix my problems, but I just don’t know how.

---

<div class="post-metadata">

**Author:** ![Thorstrum](https://avatars.discourse-cdn.com/v4/letter/t/858c86/32.png) [@Thorstrum](https://discourse.processing.org/u/Thorstrum)\
**Post date:** [February 24, 2026, 5:42am UTC](https://discourse.processing.org/t/whats-a-better-way-to-write-my-code-so-i-dont-keep-getting-null-pointer-exceptions/47958/2 "2026-02-24T05:42:26Z")

</div>

nevermind, found get()
