【发布时间】:2010-09-12 17:39:13
【问题描述】:
我有一个如下构造函数:
public Agent(){
this.name = "John";
this.id = 9;
this.setTopWorldAgent(this, "Top_World_Agent", true);
}
我在方法调用中遇到空指针异常。这似乎是因为我在 setTopWorldAgent 方法中使用“this”作为参数。通过删除此方法调用,一切看起来都很好。为什么会这样?有其他人经历过吗?
【问题讨论】:
-
我猜 setTopWorldAgent 中的代码是发生异常的地方。也许您可以添加异常的堆栈跟踪和该方法的代码。
-
我想看看提问者的最终解决方案是什么。
-
这叫自变量,不是参数。
标签: java constructor methods call this