开发者

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 = (GlobalStat开发者_如何学Goe) 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?


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

<application android:name=".AppObject">

You might find some help here


Have you tried (GlobalState) getApplicationContext(); That's the only method call I use when I use my own application class. You can also just cut the name to android:name="GlobalState" (at least in 2.2)

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜