Getting "Null Pointer Exception" Error, can't figure out why.
in
Core Library Questions
•
7 months ago
Hey folks,
I'm still very much a newbie at Processing––taking my first beginner class, and I'm doing this guitar tuner project using minim sounds.
I get this particular Null Pointer error if I rapidly play sounds in my sketch, but only if I click out of the sketch. The error doesn't stop my program from working, but the moment I x out of it, the error pops up in the main Processing window.
Here's the error:
And below is my main program code. I apologize for the length! I know an expert programmer could write this much more efficiently, so I apologize for my newbish-ness :-p.
Any help would be fantastic––thanks!
I'm still very much a newbie at Processing––taking my first beginner class, and I'm doing this guitar tuner project using minim sounds.
I get this particular Null Pointer error if I rapidly play sounds in my sketch, but only if I click out of the sketch. The error doesn't stop my program from working, but the moment I x out of it, the error pops up in the main Processing window.
Here's the error:
- java.lang.NullPointerException
at processing.mode.java.runner.Runner.findException(Runner.java:707)
at processing.mode.java.runner.Runner.reportException(Runner.java:652)
at processing.mode.java.runner.Runner.exception(Runner.java:595)
at processing.mode.java.runner.EventThread.exceptionEvent(EventThread.java:367)
at processing.mode.java.runner.EventThread.handleEvent(EventThread.java:255)
at processing.mode.java.runner.EventThread.run(EventThread.java:89)
Exception in thread "Thread-5" java.lang.NullPointerException
at ddf.minim.javasound.JSBaseAudioRecordingStream.readBytes(Unknown Source)
at ddf.minim.javasound.JSBaseAudioRecordingStream.mRead(Unknown Source)
at ddf.minim.javasound.JSBaseAudioRecordingStream.read(Unknown Source)
at ddf.minim.javasound.JSAudioOutput.readStream(Unknown Source)
at ddf.minim.javasound.JSAudioOutput.run(Unknown Source)
java.lang.NullPointerException
at processing.mode.java.runner.Runner.findException(Runner.java:707)
at processing.mode.java.runner.Runner.reportException(Runner.java:652)
at processing.mode.java.runner.Runner.exception(Runner.java:595)
at processing.mode.java.runner.EventThread.exceptionEvent(EventThread.java:367)
at processing.mode.java.runner.EventThread.handleEvent(EventThread.java:255)
at processing.mode.java.runner.EventThread.run(EventThread.java:89)
Exception in thread "Thread-6" java.lang.NullPointerException
at ddf.minim.javasound.JSBaseAudioRecordingStream.readBytes(Unknown Source)
at ddf.minim.javasound.JSBaseAudioRecordingStream.mRead(Unknown Source)
at ddf.minim.javasound.JSBaseAudioRecordingStream.read(Unknown Source)
at ddf.minim.javasound.JSAudioOutput.readStream(Unknown Source)
at ddf.minim.javasound.JSAudioOutput.run(Unknown Source)
And below is my main program code. I apologize for the length! I know an expert programmer could write this much more efficiently, so I apologize for my newbish-ness :-p.
- //FONT(S):
PFont b; //Size 48 Font.
PFont c; //Size 20 Font.
//MINIM:
import ddf.minim.*; //import minim library.
Minim minim; //Minim object.
AudioPlayer [] BassPlayer = new AudioPlayer[4]; //AudioPlayer Array.
//ARRAYS:
Ellipses[] shadows = new Ellipses[2]; //Black ellipses that forms "shadow" of guitar.
Quads[] qshadow = new Quads[1]; //Black quad that forms "shadow" of guitar neck.
Ellipses[] body = new Ellipses[2]; //Guitar Body Parts.
Ellipses[] sh = new Ellipses[1]; //Sound Hole.
Quads[] gneck = new Quads[1]; //Guitar Neck.
Quads[] gbridge = new Quads[1]; //Guitar Bridge.
Points[] bpoints = new Points[4]; //Bridge Points.
Lines[] bline = new Lines[1]; //Bridge Line.
Lines[] gstrings = new Lines[6]; //Guitar Strings.
Triangles[] tuners = new Triangles[4]; //Guitar Tuners.
Ellipses[] soundbuttons = new Ellipses[4]; //Sound Buttons.
void setup() {
size(1000,700);
//FONT(S);
b = loadFont("ACaslonPro-Italic-48.vlw");
c = loadFont("ACaslonPro-Italic-20.vlw");
//MINIM SETUP:
minim = new Minim(this); //IMPORT Minim Array Files.
BassPlayer[3] = minim.loadFile("e_string.mp3"); //Imported Sounds.
BassPlayer[2] = minim.loadFile("a_string.mp3");
BassPlayer[1] = minim.loadFile("d_string.mp3");
BassPlayer[0] = minim.loadFile("g_string.mp3");
//ARRAYS:
shadows[0] = new Ellipses(color(0),200,500,300,260); //"Shadow" Ellipse #1 f/Body.
shadows[1] = new Ellipses(color(0),400,397,220,240); //"Shadow" Ellipse #2 f/Body.
qshadow[0] = new Quads(color(0),450,312,485,377,810,180,780,120); //"Shadow" Quad f/Neck.
body[0] = new Ellipses(color(#D3CE6B),200,485,300,260); //"Body" Ellipse #1.
body[1] = new Ellipses(color(#D3CE6B),400,390,230,230); //"Body" Ellipse #2.
sh[0] = new Ellipses(color(#644133),320,430,120,120); //"Sound Hole" Ellipse.
gneck[0] = new Quads(color(#D3CE6B),450,312,485,370,810,170,780,120); //"Neck" Quad.
gbridge[0] = new Quads(color(#644133),160,470,190,450,260,530,220,550); //"Bridge" Quad.
bpoints[0] = new Points(178,478);//Bridge Points.
bpoints[1] = new Points(188,490);
bpoints[2] = new Points(197,503);
bpoints[3] = new Points(206,516);
bline[0] = new Lines(color(0),185,460,238,530);
gstrings[0] = new Lines(color(#201ED3),765,140,760,130);
gstrings[1] = new Lines(color(#0E9D52),780,170,785,180);
gstrings[2] = new Lines(color(#C00000),175,480,680,180); //E string.
gstrings[3] = new Lines(color(#201ED3),188,490,765,140); //A string.
gstrings[4] = new Lines(color(#0E9D52),197,503,780,170); //D string.
gstrings[5] = new Lines(color(#D01ED3),206,516,715,225); //G string.
tuners[0] = new Triangles(680,180,630,150,700,110); //E tuner.
tuners[1] = new Triangles(760,130,715,100,770,70); //A tuner.
tuners[2] = new Triangles(785,180,780,240,850,200); //D tuner.
tuners[3] = new Triangles(715,225,700,290,765,250); //G tuner.
soundbuttons[0] = new Ellipses(color(#C00000),550,600,50,50);//Sound Buttons
soundbuttons[1] = new Ellipses(color(#201ED3),650,600,50,50);
soundbuttons[2] = new Ellipses(color(#0E9D52),750,600,50,50);
soundbuttons[3] = new Ellipses(color(#D01ED3),850,600,50,50);
}//END SETUP.
void draw() {
background(210);
smooth();
//FONT(S):
textFont(b,48); //Size 48 Font.
fill(0);
text("Ben's Bass Guitar Tuner",10,50);
text("E",530,550);
text("A",630,550);
text("D",730,550);
text("G",830,550);
textFont(c,20); //Size 20 Font.
fill(0);
text("Standard Guitar (E,A,D,G) tuning",10,70);
text("To use, press corresponding buttons",575,500);
//LOOPS:
for(int i=0; i<shadows.length; i++) { // "Shadow" Ellipses.
shadows[i].shadowCircles();
}
for(int i=0; i<qshadow.length; i++) { // "Shadow" Neck.
qshadow[i].shadowNeck();
}
for(int i=0; i<body.length; i++) { //Guitar Body.
body[i].bodyCircles();
}
for(int i=0; i<sh.length; i++) { //Sound Hole.
sh[i].soundHole();
}
for(int i=0; i<gneck.length; i++) { //Guitar Neck.
gneck[i].Neck();
}
for(int i=0; i<gbridge.length; i++) { //Bridge.
gbridge[i].Bridge();
}
for(int i=0; i<bpoints.length; i++) { //Bridge Points.
bpoints[i].BridgePoints();
}
for(int i=0; i<bline.length; i++) { //Bridge Line.
bline[i].BridgeLine();
}
for(int i=0; i<gstrings.length; i++) { //Strings.
gstrings[i].GuitarStrings();
}
for(int i = 0; i<tuners.length; i++) { //Tuners.
tuners[i].GuitarTuners();
}
for(int i=0; i<soundbuttons.length; i++) { //Sound Buttons.
soundbuttons[i].sButtons();
}
//MOUSE PRESSES:
if (mousePressed) { //E STRING SOUND
if((dist(550,600,mouseX,mouseY))<50) {
stroke(#C00000);
strokeWeight(10);
line(175,480,680,180);
BassPlayer[3].play();
BassPlayer[3].rewind();
}
}
if (mousePressed) { //A STRING SOUND
if((dist(650,600,mouseX,mouseY))<50) {
stroke(#201ED3);
strokeWeight(10);
line(188,490,765,140);
BassPlayer[2].play();
BassPlayer[2].rewind();
}
}
if (mousePressed) { //D STRING SOUND
if((dist(750,600,mouseX,mouseY))<50) {
stroke(#0E9D52);
strokeWeight(10);
line(197,503,780,170);
BassPlayer[1].play();
BassPlayer[1].rewind();
}
}
if (mousePressed) { //G STRING SOUND
if((dist(850,600,mouseX,mouseY))<50) {
stroke(#D01ED3);
strokeWeight(10);
line(206,516,715,225);
BassPlayer[0].play();
BassPlayer[0].rewind();
}
}
} //END DRAW.
/* "void stop" prevents Minim from "freaking out"
Without it, the "NullPointerException Error" would eventually be produced*/
void stop() {
super.stop();
}
Any help would be fantastic––thanks!
1