This has to do with using the Robolectric framework for unit testing
on android. I'm getting a null pointer exception on code which has no
problem when running normally. I'm just starting on the roboelectric,
so it's probably pretty simple.
I noticed another member had the same problem, but apparently it
hasn't been resolved, so I'm posting just in case I missed something.
Here is the calling code:
@Test
public void testInitUtilsInitSequenceNumberIsRandom() {
// create an activity for reference
InitUtils initUtils = new InitUtils();
// do static initialization to parse questions into memory
InitUtils.initialize(initUtils); // <============ the call from
roboelectric framework
// retreive app state
AppState appState = (AppState) initUtils.getApplicationContext();
// fill in later
fail("not implemented");
}
Here is the method called within in InitUtils which crashes
/** * Loads the XML into the {@see mQuestions} class member variable *
*/ public static void initializeQuestions(Activity activity, AppState
appState) {
/* create XML Parser */
XmlResourceParser questionBatch;
/* local question variable */
Question question = null;
/* retrieve the XML for parsing */
// =============== This returns null
==============================
questionBatch = activity.getResources().getXml(R.xml.questions);
/* Parse the XML */
int eventType = -1;
/* iterate through XML */
while (eventType != XmlResourceParser.END_DOCUMENT) {
if (eventType == XmlResourceParser.START_TAG) {
/* Get the questions */
// ================================= NPE exception
======================
String strName = questionBatch.getName();
...etc
Is there something special I need to do for this to retrieve the
resource?
http://stackoverflow.com/questions/5340239/robolectriceclipse-cant-find-resources
Jack
I also posted on SO -