stumped by NullPointerException errors

From: David (dave_shattuck_at_hotmail.com)
Date: 05/07/04


Date: 6 May 2004 17:00:21 -0700

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



Relevant Pages

  • stumped by NullPointerException errors
    ... Class 2 saves the address of Class 1's pointer within a private member ... Class 2 is able to access Class 1 through the private member variable ...
    (comp.lang.java.programmer)
  • stumped by NullPointerException errors
    ... Class 2 saves the address of Class 1's pointer within a private member ... Class 2 is able to access Class 1 through the private member variable ...
    (comp.lang.java.help)
  • Re: Casting of pointer to member functions
    ... cast it back before any usage. ... The example above will compile only if /ymg compiler switch ... the bits that pointer is ... calling a member function through such pointer is ...
    (microsoft.public.vc.language)
  • Re: Class members, pointers or not?
    ... > Is it best to declare class member objects as pointers or not pointers? ... using pointer members (and reference members) ...
    (comp.lang.cpp)
  • Re: Forward references and recursion
    ... It needs not only the name, but it need to know the declaration, to calculate ... A workaround, is to change the member as the pointer to the list, ... Probably you needs just a outside lists of plain data classes, ...
    (microsoft.public.vc.stl)