开发者

RuntimeException when trying to use android.app.Application

I'm trying to use a custom class (be.myname.rssreader.util.Global) extending android.app.Application, but when I try to use its accessors, I get the following exception:

02-23 11:42:12.973: ERROR/AndroidRuntime(2050): java.lang.RuntimeException: Unable to start activity ComponentInfo{be.myname.rssreader/be.myname.rssreader.view.RSSReader}: java.lang.NullPointerException

Before you ask, yes, it's in my manifest, as follows:

<application android:name=".util.Global" android:icon="@drawable/icon"
        android:label="@string/app_name" android:debuggable="true">

The code where the exception is thrown is this:

global.setService(new FeedService(getApplicationContext()));

It's placed in the onCreate of my main Activity, immdiately after the calls to super.onCreate and setContentVi开发者_开发问答ew.

Any ideas why this keeps throwing that exception?

Thanks.


Did you check global isn't null ?

EDIT : If you're trying to access your Application class in an Activity or a Service, you have to retrieve it like that :

/* e.g. Global is the name of your class which extends Application */
this.global = (Global) getApplication()


Check this link. Try ./emulator -wipe -data before running your application.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜