2011-03-31 118 views
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块示出。

+0

如果您仔细阅读日志,则可以找到发生此错误的确切行号。 – mudit 2011-03-31 14:13:17

+4

你正在检查index1 2red13 2011-03-31 14:14:51

+0

@mudit - 我只是得到这个词NullPointerException,在我的logcat中没有其他细节 – 2011-03-31 14:24:59

回答

0

尝试运行logcat-v long。这应该打印出所有可用的元数据......并希望完整的堆栈跟踪。

您还需要调用的方法Log.e东西三个参数版本是这样的:

Log.e("yourClass", "unexpected exception", e); 

目前你正在做什么是记录e.toString()不包括完整的堆栈跟踪。