D
David
Anyone up to a challenge? I am using pointers in Java so that one
object can update another. I have done this in the program I am
working on without a problem. Now, I am using it again and
encountering a NullPointerException error. It does not make sense.
Here's the logic I've been using:
Class 1 instantiates Class 2 using a constructor which allows Class 1
to pass a pointer of itself to Class 2
Class 2 saves the address of Class 1's pointer within a private member
variable "pc"
Class 1 has protected member function "memberfunction"
Class 2 is able to access Class 1 through the private member variable
"pc"
In code:
public class1 {
class1() {
class2(this);
}
protected void memberfunction() {
// does something usefull
}
}
public class2 {
class1 pc;
class2(class1 callback) {
pc=callback;
}
private anotherfunction() {
pc.memberfunction()
}
}
Why, when I wrote my program (using threads which can access their
parent's member functions) I had no problem but now I am getting a
null pointer error? Can anyone think of reasons I would receive this
error using the scenerio above? This is a broad question - hopefully
I've given enough information for some answers!
David
object can update another. I have done this in the program I am
working on without a problem. Now, I am using it again and
encountering a NullPointerException error. It does not make sense.
Here's the logic I've been using:
Class 1 instantiates Class 2 using a constructor which allows Class 1
to pass a pointer of itself to Class 2
Class 2 saves the address of Class 1's pointer within a private member
variable "pc"
Class 1 has protected member function "memberfunction"
Class 2 is able to access Class 1 through the private member variable
"pc"
In code:
public class1 {
class1() {
class2(this);
}
protected void memberfunction() {
// does something usefull
}
}
public class2 {
class1 pc;
class2(class1 callback) {
pc=callback;
}
private anotherfunction() {
pc.memberfunction()
}
}
Why, when I wrote my program (using threads which can access their
parent's member functions) I had no problem but now I am getting a
null pointer error? Can anyone think of reasons I would receive this
error using the scenerio above? This is a broad question - hopefully
I've given enough information for some answers!
David