Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/304.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/eclipse/8.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 将处理集成到Eclipse时的NullPointerException_Java_Eclipse_Processing - Fatal编程技术网

Java 将处理集成到Eclipse时的NullPointerException

Java 将处理集成到Eclipse时的NullPointerException,java,eclipse,processing,Java,Eclipse,Processing,我目前正在尝试将现有的处理项目集成到Eclipse中。有两个类,TagCloud和Tag,前者是后者的控制器。在TagCloud中,我有以下代码片段: for (int i = 0; i < NUM_RELATIONS; i++) { println("i: " + i); tags.get(i).refTagsMap(tagsMap); tags.get(i).setLinks(); //Randomly a

我目前正在尝试将现有的处理项目集成到Eclipse中。有两个类,TagCloud和Tag,前者是后者的控制器。在TagCloud中,我有以下代码片段:

for (int i = 0; i < NUM_RELATIONS; i++) {
          println("i: " + i);
          tags.get(i).refTagsMap(tagsMap);
          tags.get(i).setLinks();
          //Randomly assign a location to  the first tag.
          System.out.println("Tag from map: " + tags.get(i));
          for(int j = 0; j < tags.size(); j++)
              System.out.println(j + " " + tags.get(j));
          tags.get(i).drawTag();
        }

        for(int i = 0; i < NUM_RELATIONS; i++) {
          println("Drawing tags for tag: " + i); 
          tags.get(i).drawLinks();
        }
下面是
drawTag()
drawLink
方法

public void drawTag() {
  parent.noFill();
  parent.stroke(255);
  parent.strokeWeight(3);    
  float x = location.x;
  float y = location.y;
  //Create the rectangle frame
  frame = parent.createShape(parent.RECT, x, y, 100, 80);
  //Add it to the canvas
  parent.shape(frame);

  //Write the text
  parent.text(topic, x + 15, y + 25);
}


public void drawLinks() {
    System.out.println();
    parent.stroke(255);
    parent.strokeWeight(1);
    for(int i = 0; i < linkKeys.size(); i++)
    {
      Tag linkedTag = links.get(linkKeys.get(i));
      System.out.println(linkedTag);
      int x = (int)linkedTag.getLocation().x;
      int y = (int)linkedTag.getLocation().y;
      PShape line = parent.createShape(parent.LINE, location.x, location.y, x, y);
      //Add the shape to the 
      parent.shape(line);
      linkLines.add(line);
    }
  }
}
public void drawTag(){
parent.noFill();
父母中风(255);
亲本.冲程重量(3);
浮动x=位置x;
浮动y=位置y;
//创建矩形框架
frame=parent.createShape(parent.RECT,x,y,100,80);
//将其添加到画布中
形状(框架);
//写课文
父文本(主题,x+15,y+25);
}
公共空间链接(){
System.out.println();
父母中风(255);
亲本.冲程重量(1);
对于(int i=0;i
父项是在标记的构造函数中传递的PApplet。

因此我发现了错误。
在我的
TagsCloud
对象的构造函数中,我正在初始化
Tag
对象,并试图将对TagsCloud对象的引用传递给它。但是,
TagsCloud
构造函数尚未完成执行,因此
TagsCloud
对象尚未完全初始化,因此上面示例中的
NullPointerException

哪一行位于TagCloud.main(TagCloud.java:97),它是Tags cloud的主要函数调用:PApplet.main(新字符串[]{“--present”,“TagCloud”});我在
drawTag()
的开头添加了一行
System.out.println(父项)
,它将打印以下内容:
TagCloud[panel0,0,0,0x0,invalid,layout=java.awt.FlowLayout]
,这意味着它不是空的,对吗?刷新页面我犯了一个错误并编辑了它now@Satre是的。我的分析不正确。即使堆栈跟踪也显示它进入了
noFill()
父项
不是
null
。很抱歉指导您出错。根本原因不在您发布的代码中。您可以下载整个项目吗?(或者您可以创建一个复制此内容的最小示例?)
public void drawTag() {
  parent.noFill();
  parent.stroke(255);
  parent.strokeWeight(3);    
  float x = location.x;
  float y = location.y;
  //Create the rectangle frame
  frame = parent.createShape(parent.RECT, x, y, 100, 80);
  //Add it to the canvas
  parent.shape(frame);

  //Write the text
  parent.text(topic, x + 15, y + 25);
}


public void drawLinks() {
    System.out.println();
    parent.stroke(255);
    parent.strokeWeight(1);
    for(int i = 0; i < linkKeys.size(); i++)
    {
      Tag linkedTag = links.get(linkKeys.get(i));
      System.out.println(linkedTag);
      int x = (int)linkedTag.getLocation().x;
      int y = (int)linkedTag.getLocation().y;
      PShape line = parent.createShape(parent.LINE, location.x, location.y, x, y);
      //Add the shape to the 
      parent.shape(line);
      linkLines.add(line);
    }
  }
}