I am seeing a lot of NullPointerException in my code at the moment
from public static variables.

I use these variables to store, e.g., my image library (used in
Activities throughout my code). All of them are initialized in the
OnCreate of my apps Base activity, and I check that they are
initialized in OnResume just to be certain (and initialize them if
they have somehow become nulled).

// Main APP Activity
MainActivity {
public static GlobalObject lib;

void OnCreate() {
  if (lib == null)
    lib = new GlobalObject();
}

void OnResume() {
  if (lib == null)
    lib = new GlobalObject();
}

}

// Some other activity instantiated later
OtherActivity {
void onCreate() {
  lib.doSomething();  // This line will sometimes fail with a
NullPointerException
}

}

I am quite unable to recreate the situation in which this
NullPointerException occurs. As I understand the activity lifecycle,
it should not be possible for lib to be null when OtherActivity is
created (if OtherActivity is in memory, MainActivity's static
variables should also be in memory and if the app is killed, it should
start over from MainActivity?), but that is the error I seem to be
getting.

Suggestions, anyone? I suppose I am probably overlooking something
simple, but I just can't see it.

Regards,

Michael A.

-- 
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en

Reply via email to