I'm current working on an RFID program. Whenever a key is pressed the following error occurs
Exception in thread "Animation Thread" java.lang.NullPointerException
at optimized.keyPressed(optimized.java:222)
at processing.core.PApplet.handleKeyEvent(PApplet.java:1724)
at processing.core.PApplet.dequeueKeyEvents(PApplet.java:1707)
at processing.core.PApplet.handleDraw(PApplet.java:1412)
at processing.core.PApplet.run(PApplet.java:1305)
at java.lang.Thread.run(Thread.java:595)
Code:
char currentTags[][];
void keyPressed()
{
print(" "+ key);
if (key == '\n')
{
//move to next tag
g++;
if(g>6){
g=0;
}
}
else
{
//get the character input from the reader and store into the array
for(i=0;i<16;i++){
currentTags[i][g] = key;
}
}
//check to see which tags are present
for(k=0;k<7;k++){
for(i=0;i<16;i++){
if(currentTags[i][k] != tag1[i]){
tagsPresent[0] = 0;
}else{tagsPresent[0] = 1;}
if(currentTags[i][k] != tag2[i]){
tagsPresent[1] = 0;
}else{tagsPresent[1] = 1;}
}
if(currentTags[i][k] != tag3[i]){
tagsPresent[2] = 0;
}else{tagsPresent[2] = 1;}
if(currentTags[i][k] != tag4[i]){
tagsPresent[3] = 0;
}else{tagsPresent[3] = 1;}
if(currentTags[i][k] != tag5[i]){
tagsPresent[4] = 0;
}else{tagsPresent[4] = 1;}
if(currentTags[i][k] != tag6[i]){
tagsPresent[5] = 0;
}else{tagsPresent[5] = 1;}
if(currentTags[i][k] != tag7[i]){
tagsPresent[6] = 0;
}else{tagsPresent[6] = 1;}
}
for(i=0;i<7;i++){
if(tagsPresent[i] == 1){
numTagsPresent++;
}
}
}
I suspect it has something to do with the way I initialized the 2 dimensional array. (New to processing and Java) Thanks for the help!