Search code examples
androidandroid-2.1-eclair

Android; getApplication() returning null, can't see why


(It's quite late here, so could be overseeing something really simple..)

I've got the following class :

public class GlobalState extends Application {
    private Stub stub = new Stub();

    public Stub getStub() {
        return stub;
    }
}

and this in my application tag on android manifest..

<application android:name="com.jameselsey.observerpattern.GlobalState"
...
>

Now, whenever I try to grab this, such as in a Service class, I get a null pointer (gs is null), I'm using the following

private GlobalState gs = (GlobalState) getApplication();
private Stub stub = gs.getStub();

I've got a similar setup working in another app, so I really can't see why this isn't working since I've based this on the one that does work.

Any ideas?


Solution

  • Did you update the application tag in AndroidManifest.xml with your class name?

    <application android:name=".AppObject">

    You might find some help here