我有两个 android 活动类。主要活动类包含 xml 解析,我试图将从那里获得的数据传递给另一个活动类,该活动类将把它放入所有数据的列表视图中。下面是 xml 解析主要活动的问题是,当我运行程序时它显示 nullpointer exception 。我被困在这里,任何人都可以帮助我错误在哪里。提前谢谢
enter code here
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
// setContentView(R.layout.main);
try {
stringXmlContent = getEventsFromAnXML(this);
Intent i=new Intent(LocationSidActivity.this,FacebookData.class);
i.putStringArrayListExtra("language", stringXmlContent);
startActivity(i);
// myXmlContent.setText(stringXmlContent);
} catch (XmlPullParserException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
private ArrayList<String> getEventsFromAnXML(Activity activity)
throws XmlPullParserException, IOException {
ArrayList<String> al = new ArrayList<String>();
Resources res = activity.getResources();
XmlResourceParser xpp = res.getXml(R.xml.myxml);
xpp.next();
int eventType = xpp.getEventType();
while (eventType != XmlPullParser.END_DOCUMENT) {
if (eventType == XmlPullParser.START_DOCUMENT) {
al.add(xpp.getName());
} else if (eventType == XmlPullParser.START_TAG) {
//if ((xpp.getName()).compareTo("id") != 0) {
al.add(xpp.getName());
//} else {
//eventType = xpp.next();
}
else if (eventType == XmlPullParser.TEXT) {
al.add(xpp.getText());
}
eventType = xpp.next();
}
return al;
}
}