处理并弹出空指针异常

发布于 2024-10-08 20:00:15 字数 2434 浏览 5 评论 0原文

所以我正在使用Processing IDE并不断收到这个奇怪的空指针异常。

线程“main”中的异常 java.lang.NullPointerException
在处理.core.PApplet.displayable(PApplet.java:9944)
在处理.core.PApplet.main(PApplet.java:7425)

这就是我得到的所有信息,所以我什至无法追踪到它发生的位置。这是我的代码

import TUIO.*;

TuioProcessing tuioClient;
Vector tuioCursorList;
Point cols[][];


void setup(){
  size(1440,900);
  tuioClient = new TuioProcessing(this);
  tuioCursorList = tuioClient.getTuioCursors();
  init();
}

void draw(){
  background(0);


}

void init(){
  cols = new Point[width][height];
  for(int i = 0; i<width;i++){
    for(int x = 0; x<height;x++){
      cols[i][x] = new Point(i,x);
    }
  }
}

class Point{

  int x, y;
  boolean alive;
  int life;
  int pointColor;

  Point(int _x, int _y){
    x = _x;
    y = _y;
    pointColor = 0;
    alive = false;
    fill(pointColor);
    point(x, y);

  }

  void checkStatus(){
    if(alive = true){
      isAlive();
    } 
    else{
      isDead();
    }
  }

  void isDead(){
    pointColor = 0;
    life = 0;
  }

  void isAlive(){
    pointColor = 255;
    life = 100;
  }

  void kill(){
    life--; 
  }

}

// called when an object is added to the scene
void addTuioObject(TuioObject tobj) {
  println("add object "+tobj.getSymbolID()+" ("+tobj.getSessionID()+") "+tobj.getX()+"     "+tobj.getY()+" "+tobj.getAngle());
}

// called when an object is removed from the scene
void removeTuioObject(TuioObject tobj) {
  println("remove object "+tobj.getSymbolID()+" ("+tobj.getSessionID()+")");
}

// called when an object is moved
void updateTuioObject (TuioObject tobj) {
  println("update object "+tobj.getSymbolID()+" ("+tobj.getSessionID()+")     "+tobj.getX()+" "+tobj.getY()+" "+tobj.getAngle()
    +" "+tobj.getMotionSpeed()+" "+tobj.getRotationSpeed()+" "+tobj.getMotionAccel()+"     "+tobj.getRotationAccel());
}


// called when a cursor is added to the scene
void addTuioCursor(TuioCursor tcur) {
  println(tcur.getX()+", "+tcur.getY());
}

// called when a cursor is moved
void updateTuioCursor (TuioCursor tcur) {
  println(tcur.getSessionID() + " - " + tcur.getX()+", "+tcur.getY());
}

// called when a cursor is removed from the scene
void removeTuioCursor(TuioCursor tcur) {
}

// called after each message bundle
// representing the end of an image frame
void refresh(TuioTime bundleTime) { 
  redraw();
}

,任何人都可以帮我找出这个奇怪的错误。任何帮助将不胜感激

so i am using the Processing IDE and keep getting this strange null pointer exception.

Exception in thread "main" java.lang.NullPointerException
at processing.core.PApplet.displayable(PApplet.java:9944)
at processing.core.PApplet.main(PApplet.java:7425)

that's all the info i get so i can't even trace to where it is occuring. here is my code

import TUIO.*;

TuioProcessing tuioClient;
Vector tuioCursorList;
Point cols[][];


void setup(){
  size(1440,900);
  tuioClient = new TuioProcessing(this);
  tuioCursorList = tuioClient.getTuioCursors();
  init();
}

void draw(){
  background(0);


}

void init(){
  cols = new Point[width][height];
  for(int i = 0; i<width;i++){
    for(int x = 0; x<height;x++){
      cols[i][x] = new Point(i,x);
    }
  }
}

class Point{

  int x, y;
  boolean alive;
  int life;
  int pointColor;

  Point(int _x, int _y){
    x = _x;
    y = _y;
    pointColor = 0;
    alive = false;
    fill(pointColor);
    point(x, y);

  }

  void checkStatus(){
    if(alive = true){
      isAlive();
    } 
    else{
      isDead();
    }
  }

  void isDead(){
    pointColor = 0;
    life = 0;
  }

  void isAlive(){
    pointColor = 255;
    life = 100;
  }

  void kill(){
    life--; 
  }

}

// called when an object is added to the scene
void addTuioObject(TuioObject tobj) {
  println("add object "+tobj.getSymbolID()+" ("+tobj.getSessionID()+") "+tobj.getX()+"     "+tobj.getY()+" "+tobj.getAngle());
}

// called when an object is removed from the scene
void removeTuioObject(TuioObject tobj) {
  println("remove object "+tobj.getSymbolID()+" ("+tobj.getSessionID()+")");
}

// called when an object is moved
void updateTuioObject (TuioObject tobj) {
  println("update object "+tobj.getSymbolID()+" ("+tobj.getSessionID()+")     "+tobj.getX()+" "+tobj.getY()+" "+tobj.getAngle()
    +" "+tobj.getMotionSpeed()+" "+tobj.getRotationSpeed()+" "+tobj.getMotionAccel()+"     "+tobj.getRotationAccel());
}


// called when a cursor is added to the scene
void addTuioCursor(TuioCursor tcur) {
  println(tcur.getX()+", "+tcur.getY());
}

// called when a cursor is moved
void updateTuioCursor (TuioCursor tcur) {
  println(tcur.getSessionID() + " - " + tcur.getX()+", "+tcur.getY());
}

// called when a cursor is removed from the scene
void removeTuioCursor(TuioCursor tcur) {
}

// called after each message bundle
// representing the end of an image frame
void refresh(TuioTime bundleTime) { 
  redraw();
}

can anyone help me figure out this strange error. any help would be much appreciated

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

ゃ人海孤独症 2024-10-15 20:00:15

将您的 init() 函数重命名为其他名称。您实际上是重写了Processing 内置类的init() 函数。

Rename your init() function to something else. You are effectively overriding the init() function of Processing's built-in classes.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文