Does "this" refer to the OnClickListener button listener object? Often this is an inner member class of the activity so it would work if you take the "this." off. But you seem to have something a little more complicated going on. Maybe we need to see the OnClickListener code.
On Oct 15, 9:59 am, Dianne Hackborn <[email protected]> wrote: > Oh if it isn't in the same package, of course that doesn't work -- it would > return the application object for -its- package. > > > > On Thu, Oct 15, 2009 at 2:31 AM, Stefan <[email protected]> wrote: > > > Nope. Right now, for testing purposes, it is triggered through a > > button click. > > > I've also included android:name="AppObject" within the <application>- > > tag of the Manifest. And the initialization of the AppObject seems to > > work properly. > > > The only thing that doesn't work is calling AppObject appObj = > > (AppObject)this.getApplication(); from an Activity that is not in the > > same package as the AppObject (which is in the "main" package). As > > soon as I move this Activity into the "main" package it works properly > > and (AppObject)this.getApplication(); returns the Application Object. > > > On Oct 9, 8:26 pm, Dianne Hackborn <[email protected]> wrote: > > > Are you calling it in the constructor? The activity is not yet fully > > > initialized at that point. > > > > On Fri, Oct 9, 2009 at 2:28 AM, Stefan <[email protected]> wrote: > > > > > I'm running the following line in an Activity, which is within the > > > > same application, but in a different package: > > > > AppObject appObj = (AppObject)this.getApplication(); // FYI: > > > > AppObject is my extension class of Application. > > > > > It returns only a null pointer, while when I move it to the "main" > > > > package and run it from there it returns the application reference as > > > > expected. > > > > > I've defined the activity in my AndroidManifest.xml with the full > > > > qualified class name, since it is in another package: <activity > > > > android:name="com.foo.bar.TestActivity"></activity> > > > > > Any ideas of what I've to do different? > > > > > Thanks > > > > -- > > > Dianne Hackborn > > > Android framework engineer > > > [email protected] > > > > Note: please don't send private questions to me, as I don't have time to > > > provide private support, and so won't reply to such e-mails. All such > > > questions should be posted on public forums, where I and others can see > > and > > > answer them. > > -- > Dianne Hackborn > Android framework engineer > [email protected] > > Note: please don't send private questions to me, as I don't have time to > provide private support, and so won't reply to such e-mails. All such > questions should be posted on public forums, where I and others can see and > answer them. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Android Developers" group. To post to this group, send email to [email protected] To unsubscribe from this group, send email to [email protected] For more options, visit this group at http://groups.google.com/group/android-developers?hl=en -~----------~----~----~----~------~----~------~--~---

