I've been having some issues reading an XML file in my 'res' folder and I think I've narrowed it down to an issue with my apps 'activity'.
I keep getting a NullPointerException on line # 2 below.
Here is my code to get the activity. Is there a better or a right way to do this?
1. Activity activity = this;
2. Resources res = activity.getResources();
3. XmlResourceParser xpp = res.getXml(R.xml.encounters);
Here is the class:
public class XmlParser extends Activity {
public XmlParser()
throws XmlPullParserException, IOException
{
try {
XmlPullParserFactory factory = XmlPullParserFactory.newInstance();
factory.setValidating(false);
Activity activity = this;
Resources res = activity.getResources();
XmlResourceParser xpp = res.getXml(R.xml.encounters);
} catch (Exception e) {
String stackTrace = Log.getStackTraceString(e);
Log.e("error", stackTrace);
}
}
}
And I'm getting the error on the "Resources res = activity.getResources();" line... Thanks!