We closed this forum 18 June 2010. It has served us well since 2005 as the ALPHA forum did before it from 2002 to 2005. New discussions are ongoing at the new URL http://forum.processing.org. You'll need to sign up and get a new user account. We're sorry about that inconvenience, but we think it's better in the long run. The content on this forum will remain online.
IndexProgramming Questions & HelpPrograms › RFID program troubles
Page Index Toggle Pages: 1
RFID program troubles (Read 383 times)
RFID program troubles
Oct 21st, 2008, 3:23pm
 
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!
Re: RFID program troubles
Reply #1 - Oct 21st, 2008, 11:31pm
 
Classical error, you declare the array, but you must allocate its space too:

char[][] currentTags =  new char[7][16];
Page Index Toggle Pages: 1