NullPointerException on Activity Testint Tutorial

Posted by Bendik on Stack Overflow See other posts from Stack Overflow or by Bendik
Published on 2010-06-15T14:41:04Z Indexed on 2010/06/16 9:32 UTC
Read the original article Hit count: 181

Filed under:
|

Hello,

I am currently trying the activity testing tutorial (Found here), and have a problem. It seems that whenever I try to call something inside the UIThread, I get a java.lang.NullPointerException.

public void testSpinnerUI() {
    mActivity.runOnUiThread( new Runnable() {  
        public void run() {  
            mSpinner.requestFocus();
        }  
    });  
}

This gives me:

Incomplete: java.lang.NullPointerException

and nothing else. I have tried this on two different samples now, with the same result. I tried with a try/catch clause around the mSpinner.requestFocus() call, and it seems that mSpinner is null inside the thread. I have set it properly up with the setUp() function found in the same sample, and a quick assertNotNull( mSpinner ) shows me that mSpinner is in fact not null after the setUp() function. What can be the cause of this?

EDIT; ok, some more testing has been done. It seems that the application that is being tested resets between each test. This essentially makes me have to reinstantiate all variables between each test. Is this normal?

© Stack Overflow or respective owner

Related posts about android

Related posts about eclipse