因此,在查看代码时,读入xml时没有异常抛出...工作正常。
public void ReadXML() throws XmlPullParserException, IOException
{
factory = XmlPullParserFactory.newInstance();
factory.setNamespaceAware(false);
xpp = factory.newPullParser();
InputStream raw = getApplicationContext().getAssets().open("trial_info.xml");
xpp.setInput(raw,null);
}
}
问题在于doXML方法,我试图读取文本b / w两个标签... 例如
<trial>
<title>The Book</title>
<author></author>
....
</trial>
生成的错误是18:19:41.654:W / System.err(329):org.xmlpull.v1.XmlPullParserException:name expected(position:START_TAG @ 59:57 in java.io.InputStreamReader@44f049c8 )
我认为代码可能比它需要的更复杂......但是无法弄清楚错误。感谢
public void doXML() throws XmlPullParserException, IOException{
int eventType = XmlPullParser.START_TAG;
while(eventType != XmlPullParser.END_DOCUMENT)
{
if(eventType == XmlPullParser.TEXT && xpp.getText().equals(selectedTrial))
{
trialTxt = (TextView)findViewById(R.id.TrialAbbrevData);
trialTxt.setText(xpp.getText());
Log.d("what is this", xpp.getText());
while(!(eventType == XmlPullParser.END_TAG && xpp.getName().equals("...")))
{
if(eventType == XmlPullParser.START_TAG && xpp.getName().equals("trialName"))
{
eventType = xpp.next();
if(eventType == XmlPullParser.TEXT)
{
trialTxtDesc = (TextView)findViewById(R.id.TrialNameData);
trialTxtDesc.setText(xpp.getText());
Log.d("in loop",xpp.getText());
}
}
if(eventType == XmlPullParser.START_TAG && xpp.getName().equals("trialDetails"))
{
eventType = xpp.next();
if(eventType == XmlPullParser.TEXT)
{
trialTxtConc = (TextView)findViewById(R.id.TrialDescData);
trialTxtConc.setText(xpp.getText());
}
}
if(eventType == XmlPullParser.START_TAG && xpp.getName().equals("trialResults"))
{
eventType = xpp.next();
if(eventType == XmlPullParser.TEXT)
{
trialTxtConc = (TextView)findViewById(R.id.TrialResultsData);
trialTxtConc.setText(xpp.getText());
}
}
if(eventType == XmlPullParser.START_TAG && xpp.getName().equals("trialConclusion"))
{
eventType = xpp.next();
if(eventType == XmlPullParser.TEXT)
{
trialTxtConc=(TextView)findViewById(R.id.TrialConclusionData);
trialTxtConc.setText(xpp.getText());
}
}
if(eventType == XmlPullParser.START_TAG && xpp.getName().equals("whatItMeans"))
{
eventType = xpp.next();
if(eventType == XmlPullParser.TEXT)
{
trialTxtMeans = (TextView)findViewById(R.id.TrialWIMData);
trialTxtMeans.setText(xpp.getText());
}
}
eventType = xpp.next();
}
}
eventType = xpp.next();
}
}
答案 0 :(得分:0)
错误消息似乎表明XML文件中存在错误,而不是代码。