## Class B ##
public class ClassB{
public ClassB() {
}
public String getAddress() {
return "Address";
}
}
## Class A ##
public class ClassA{
private ClassB classb;
public ClassA() {
}
public void setClassb(ClassB classb) {
this.classb = classb;
}
public void getAddress() {
System.out.println(classb.getAddress());
}
}
## Main Class ##
public class MainClass{
public static void main(String[] args){
ClassA classa = new ClassA();
classa.getAddress();
}}
----------
当我运行这个程序时,它返回空指针异常。有人可以解释一下 Nullpointer Exception 的原因吗?谢谢你。我尝试过使用 setter 方法,但仍然抛出 nullpointer 异常