Friday, September 30, 2011

Re: [android-developers] Re: XML DOM Parser works in JAVA, Crashes Android App, Now XMLPullParser

I don't see your code ever assigning anything to myCh, so expect it to crash when trying to call setTheChar and setCount.

Also, that charAt(0) should really be charAt(1), no?

--
Kostya Vasilyev

01.10.2011 2:03 пользователь "Dancing Fingers" <batymahn@gmail.com> написал:
> So I'm starting to suspect my XML file. Here it is:
>
> <?xml version="1.0" encoding="UTF-8"?>
> <Chars>
> <ChPair>
> <ch>"E"</ch>
> <ct>175391</ct>
> </ChPair>
>
> <ChPair>
> <ch>"T"</ch>
> <ct>129899</ct>
> </ChPair>
>
> <ChPair>
> <ch>"A"</ch>
> <ct>110693</ct>
> </ChPair>
>
> <ChPair>
> <ch>"O"</ch>
> <ct>108786</ct>
> </ChPair>
> </Chars>
>
>
> I rewrote the method to use a XML pull parser:
>
>
> public void parseCharXmlFile(){
> Chars myCh = null;
> String nameTag= "";
>
> try {
> InputStream iStrm = getResources().openRawResource(R.xml.chars);
> XmlPullParser parser = Xml.newPullParser();
> parser.setInput(iStrm, null);
> int eventType = parser.getEventType();
> boolean done = false;
>
> while (eventType != XmlPullParser.END_DOCUMENT ){
> switch (eventType){
> case XmlPullParser.START_DOCUMENT:
> chars.clear();
> break;
> case XmlPullParser.START_TAG:
> nameTag = parser.getName();
> if (nameTag.equalsIgnoreCase("ch") ) {
> myCh.setTheChar(parser.nextText().charAt(0));
> }else if (nameTag.equalsIgnoreCase("count")) {
> myCh.setCount(Integer.parseInt(parser.nextText()));
> chars.add(myCh);
> }
> break;
> } // event switch end
> eventType = parser.next();
> }
> } catch (Exception e) {
> throw new RuntimeException(e);
> }
>
> }
>
>
> Every thing that I've read indicate that this should work. Any
> thoughts would be appreciated.
>
> Chris
>
> --
> You received this message because you are subscribed to the Google
> Groups "Android Developers" group.
> To post to this group, send email to android-developers@googlegroups.com
> To unsubscribe from this group, send email to
> android-developers+unsubscribe@googlegroups.com
> For more options, visit this group at
> http://groups.google.com/group/android-developers?hl=en

--
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to android-developers@googlegroups.com
To unsubscribe from this group, send email to
android-developers+unsubscribe@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en

No comments:

Post a Comment