Android的; getApplication()返回null,不明白为什么 [英] Android; getApplication() returning null, can't see why
问题描述
(这是相当晚了这里,所以可以监督很简单的东西..)
(It's quite late here, so could be overseeing something really simple..)
我有以下类:
public class GlobalState extends Application {
private Stub stub = new Stub();
public Stub getStub() {
return stub;
}
}
这在Android清单我的应用程序标签。
and this in my application tag on android manifest..
<application android:name="com.jameselsey.observerpattern.GlobalState"
...
>
现在,每当我试图抓住这一点,如在服务类中,我得到一个空指针(GS为空),我使用以下
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.
任何想法?
推荐答案
你与你的类名更新在AndroidManifest.xml应用程序标记?
Did you update the application tag in AndroidManifest.xml with your class name?
<application android:name=".AppObject">
您可能会发现一些帮助 rel=\"nofollow\">
You might find some help here
这篇关于Android的; getApplication()返回null,不明白为什么的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!