小编Dou*_*uga的帖子

ArrayList错误"NullPointerException"

我正在将数组更改为arrayList,有几个试验有错误"NullPointerException",代码简化如下所示,当mousePressed创建一个矩形.但仍然有同样的错误.问题是什么?

ArrayList textlines;

int xpos=20;
int ypos=20;

void setup() {
  size(1200, 768);
  ArrayList textlines = new ArrayList();
  //(Line)textlines.get(0) =textlines.add(new Line(xpos, ypos));
}

void draw() {
}


void mousePressed() {
  textlines.add(new Line(xpos, ypos));
  for (int i=0; i<textlines.size(); i++) {

    Line p=(Line)textlines.get(i);
    p.display();
  }
}


class Line {

  int x;
  int y;

  Line(int xpo, int ypo) {
    x =xpo;
    y =ypo;
  }

  void display() {
    fill(50, 50, 50);
    rect(x, y, 5, 5);
  }
}
Run Code Online (Sandbox Code Playgroud)

java processing nullpointerexception

1
推荐指数
1
解决办法
155
查看次数

标签 统计

java ×1

nullpointerexception ×1

processing ×1