我有一个错误nullPointerException
,if (stringReceive.contains(tabStock[j])){
但我不明白为什么j
数组的索引有错误tabstock
。
import oscP5.*;
import netP5.*;
OscP5 oscP5;
NetAddress myRemoteLocation;
String[] tabStock = new String[6];
String[] tabReceive = new String[6];
String stringReceive;
String oldStringReceive;
int cptEssai = 0;
int cpt = 0;
void setup() {
size(400,400);
frameRate(25);
/* start oscP5, listening for incoming messages at port 12000 */
oscP5 = new OscP5(this,12000);
myRemoteLocation = new NetAddress("127.0.0.1",12001);
tabStock[0] = "1";
tabStock[1] = "2";
tabStock[2] = "3";
tabStock[3] = "4";
tabStock[4] = "5";
tabStock[5] = "6";
//stringReceive = "A3E8F6";
tabReceive[0] = "1";
tabReceive[1] = "2";
tabReceive[2] = "3";
tabReceive[3] = "4";
tabReceive[4] = "3";
tabReceive[5] = "6";
}
void draw() {
background(0);
compare();
}
void mousePressed() {
OscMessage myMessage = new OscMessage("/test");
myMessage.add(123); /* add an int to the osc message */
/* send the message */
oscP5.send(myMessage, myRemoteLocation);
}
/* incoming osc message are forwarded to the oscEvent method. */
void oscEvent(OscMessage theOscMessage) {
/* print the address pattern and the typetag of the received OscMessage */
print("### received an osc message.");
print(" addrpattern: "+theOscMessage.addrPattern());
println(" typetag: "+theOscMessage.typetag());
stringReceive = theOscMessage.addrPattern();
println(stringReceive);
if (oldStringReceive != stringReceive){
oldStringReceive = stringReceive;
}
}
void compare() {
println(stringReceive);
println("compare()");
boolean failed=false;
int j = 0;
while (cptEssai < 3 && !failed){
for (int i= 0; i < tabStock.length; i++){
while(j<6){
if (stringReceive.contains(tabStock[j])){
print("tag existe et bien placé // ");
print("allumage de la lampe qui correspond à ce tag // ");
j++;
}
else {
print("tag n'existe pas ou mal placé // ");
print("extinction de toutes les lampes // ");
oldStringReceive = stringReceive;
if (oldStringReceive != stringReceive){
cptEssai++;
failed = true;
break;
}
else
{
if(j>0){
j--;
}
}
}
}
}
}
print("GAME OVER ! Désactivation de l'épreuve // ");
}