getApplicationContext returns null in test case (unless you sleep first)

by Dianne Hackborn » Thu, 05 Mar 2009 03:58:08 GMT

Sponsored Links
 You are calling this while the app is running, and it hasn't finished

Generally you should be very careful about directly touching app objects
like this from tests, since the test is running in a separate thread.  There
are APIs to allow you to run code on the main thread to access its objects.

Dianne Hackborn
Android framework engineer

Note: please don't send private questions to me, as I don't have time to
provide private support.  All such questions should be posted on public
forums, where I and others can see and answer them.


Other Threads

1. add text to each image in gridview

Hi, everybody

          I want to add label for each image in gridview how to do
this? I had tried with following code but it shows only images and not

my xml file as:

<?xml version="1.0" encoding="utf-8"?>
<GridView xmlns:android=""



how to do this.


2. Flexing the Expandable List Adapter

Hi All,

I just wanted to start a discussion about the approach I'm taking for
this particular Activity. Here is what I'm trying to achieve:

1) There are going to be multiple Expandable List Views, each Group
has a Title and a Button and there will be only one Child with data
based on that group.

2) Each Expandable List View has a Main Title attached to the top of

3) There will be a ScrollView to scroll through the Multiple
Expandable List Views.

Here was my solution:

Have a List View contain a TextView for the Main Title and a
Expandable List View as its child. This allows me to scroll the
multiple Expandable Lists Views easily.

I have done the work for a single Expandable List View already but I
noticed attaching a Main Title to a particular subset of groups was
difficult. Making the adapter smarter might be possible but sloppy. I
would think my solution would be a preferred method.

I just wanted some input if any of you believe that there can be
another approach that would be more acceptable. I heard making the
ExpandableListAdapter smarter to make it seems like there are multiple
Expandable List Views is possible, but it seems like the complexity
goes up quite a bit in doing so.



3. display an animated .gif image

4. Scrollview fling

5. wrap_content and fill_parent using Java

6. POSTing to WebView

7. Inyect Assistance data to the GPS