开发者

Error in parsing an XML file in Android

In my app I am trying to parse an XML file. I am able to parse it and in logcat I can find the number of tags but in my text view I am not able to view it. Now I am trying to print only one tag named as question in my text view. My text view is named flip.

Following is one part of my code:

//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);
            }
        }

In my logcat I am able to view the following lines

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

The NullPointerException is been shown from the outer catc开发者_运维技巧h block.


Try running logcat with -v long. That should print out all available metadata ... and hopefully the full stack trace.

You also need to call the three argument version of Log.e method something like this:

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

What you are currently doing is logging e.toString() which doesn't include the full stacktrace.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜