0
在我的應用程序中,我試圖解析XML文件。我能夠解析它,並在logcat中我可以找到標籤的數量,但在我的文本視圖中,我無法查看它。現在我試圖在文本視圖中只打印一個名爲question的標籤。我的文本視圖名爲flip
。解析Android中的XML文件時出錯
以下是我的代碼的一部分:
//XML parsing happens here
try
{
saxparserfactory1 = SAXParserFactory.newInstance();
saxparser1 = saxparserfactory1.newSAXParser();
xmlreader1 = saxparser1.getXMLReader();
inputstream1 = this.getResources().openRawResource(R.raw.worldhistory);
xmlreader1.setContentHandler(myXMLHandler);
xmlreader1.parse(new InputSource(inputstream1));
//getting the values of xml
flashcards = myXMLHandler.getflashcards();
flashcard = myXMLHandler.getflashcard();
try
{
o = flashcards.getFlashcard().size();
Log.e("Parsing", "flashcard size = "+o);
}
catch (Exception e)
{
Log.e("parsing",""+e);
}
String question ="" ;
if(index1 < flashcards.getFlashcard().size())
{
question = flashcards.getFlashcard().get(q[index1]).getQuestion();
Log.e("", "Qustion "+question);
Flip1.setText(question);
index1++;
}
}
catch(Exception e)
{
Log.e("",""+e);
}
}
以我的logcat我能夠查看以下行
03-31 19:25:16.578: ERROR/MyXMLHandler(10361): Flashcard created
03-31 19:25:16.578: ERROR/Parsing(10361): flashcard size = 68
03-31 19:25:16.578: ERROR/(10361): java.lang.NullPointerException
的拋出NullPointerException是來自外catch塊示出。
如果您仔細閱讀日誌,則可以找到發生此錯誤的確切行號。 – mudit 2011-03-31 14:13:17
你正在檢查index1
2red13
2011-03-31 14:14:51
@mudit - 我只是得到這個詞NullPointerException,在我的logcat中沒有其他細節 – 2011-03-31 14:24:59