首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >正在处理nullPointerException

正在处理nullPointerException
EN

Stack Overflow用户
提问于 2016-03-14 19:06:41
回答 1查看 552关注 0票数 0

我在if (stringReceive.contains(tabStock[j])){行有一个错误nullPointerException,但是我不明白为什么数组tabstock的索引j会有错误。

代码语言:javascript
复制
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   //   ");
}
EN

回答 1

Stack Overflow用户

发布于 2016-03-14 19:56:34

tabStocktabStock[j]stringReceive都是null

在该行之前打印出它们的值,以检查是哪一行。

一旦你知道它是哪一个,回溯你的代码,找出为什么它是空的。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/35985835

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档