Android parsing of XML file Null Pointer Exception

uben

New Member
I have a method that reads in an XML file, parses it and loads the individual elements into an array. The code itself works when it is included with an Activity class. It needs to be used from 2 different Activities, so I created a utility class so I can call the one copy from each Activity needed. However, when it runs from the utility class, I get a null point exception. This tells me that I'm breaking a rule of what I can do, and from where. I suspect it's related to the access to the resources, as I also tried to access a string resources (just as a test) and that also throws a NPE.Here is the utility class. The first Log.i appears in LogCat, but the 2nd does not.\[code\]class Utils extends MainActivity{String debugTag = DEBUG_TAG + "/Utils";public void loadRankFile() throws XmlPullParserException, IOException{ int eventType = -1; boolean boolFoundRanks = false; int intCounter = 0; // this line appears in LogCat Log.i(debugTag, "Inside loadRankFile utility."); // this line causes the NPE XmlResourceParser scoutRanks = getResources().getXml(R.xml.scoutranks); // this line does not appear in LogCat Log.i(debugTag, "xml file loaded");...}\[/code\]This is the code from the Activity that calls the method, above:\[code\]public class RankProgressActivity extends MainActivity{String debugTag = DEBUG_TAG + "/RankProgressActivity";Utils utilities = new Utils();@Overridepublic void onCreate(Bundle savedInstanceState){ super.onCreate(savedInstanceState); setContentView(R.layout.rank_progress); try { initSelectScout(); utilities.loadRankFile(); initSelectRank(); } catch (IOException e) { Log.i(debugTag, "Failure initializing Scout Progress activity items", e); } catch (XmlPullParserException e) { Log.e(debugTag, "Rank file parse error.", e); }...}\[/code\]I'm sure I'm making a classic mistake, but I don't see it, and I haven't been able to find guidance as of yet. Any feedback would be appreciated. I'm rather new to Java and Android, so this is very much a learning experience for me.Thank you in advance.
 
Back
Top