2

(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?

Programmer Bruce
  • 64,977
  • 7
  • 99
  • 97
Jimmy
  • 16,123
  • 39
  • 133
  • 213

2 Answers2

3

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

<application android:name=".AppObject">

You might find some help here

Raunak
  • 6,427
  • 9
  • 40
  • 52
0

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)

methodin
  • 6,717
  • 1
  • 25
  • 27