• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

problem in using SAX parser to parse xml file from assets

 
elenora Rezaie
Greenhorn
Posts: 21
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi, I want to parse a xml file from assets and insert the elements of it into SQLite database. I've written the code below but it seems that it doesn't go to startElement!



class Sura



class Aya



in the mainactivity




my xml file is such the below


in my logcat after running the project it shows

05-23 08:53:30.201: W/AndroidParseXMLActivity(904): Start
05-23 08:53:30.220: W/AndroidParseXMLActivity(904): Parse1
05-23 08:53:30.300: I/System.out(904): :name
05-23 08:53:30.379: W/System.err(904): java.lang.NullPointerException
05-23 08:53:30.461: W/System.err(904): at quranlast.ir.SuraHandler.endElement(SuraHandler.java:95)
......
it seems that it doesn't go to startElement() at all! Could anyone help me about what the problem is?

 
Ulf Dittmer
Rancher
Posts: 42969
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
it seems that it doesn't go to startElement() at all!

"seems not to" or "does not"? Adding a log statement would prove quickly which one. That log statement should print the localName as well. And you should read up on the difference between localName and qName; that is likely the issue here.
 
Steve Luke
Bartender
Posts: 4181
22
IntelliJ IDE Java Python
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What is line 95 of SuraHandler? It is in endElement() but isn't the same line as line 95 in the posted code.
 
elenora Rezaie
Greenhorn
Posts: 21
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It doesn't go to startElement() because when I run the project in logcat it doesn't show the println() messages which I wrote like the code below: and I'm sure that the problem is not related to localName or qName.



 
Steve Luke
Bartender
Posts: 4181
22
IntelliJ IDE Java Python
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
elenora Rezaie wrote:It doesn't go to startElement() because when I run the project in logcat it doesn't show the println() messages which I wrote like the code below: and I'm sure that the problem is not related to localName or qName.

Time to check your assumptions. How do you know startElement() not be called? Is it possible startElement() is called but still not print the statements you have? What is the actual localName? What is the actual qName? Don't guess, presume, or 'know' without proof.
 
Ulf Dittmer
Rancher
Posts: 42969
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It doesn't go to startElement() because when I run the project in logcat it doesn't show the println() messages which I wrote like the code below

That just proves that the "if" blocks do not get executed, it doesn't prove anything about whether or not startElement itself is called.

and I'm sure that the problem is not related to localName or qName.

So you fully understand the difference between the two, and have consciously decided to use "qName" in startElement, and "localName" in endElement?

Edit: ... which is exactly what Steve just said :-)
 
elenora Rezaie
Greenhorn
Posts: 21
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
once in startElement() and endElement() I wrote all of them as qName. and it didn't work. for the other time I wrote all of them localName and still it didn't work! then I wrote is startElement() all of them as qName and in endElement() I wrote all of them as localName but the result hasn't changed!
 
Steve Luke
Bartender
Posts: 4181
22
IntelliJ IDE Java Python
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
So what are the values of localName and qName when startElement() is called? You can't get away with saying "startElement() isn't called" because you haven't any proof of that, and it likely isn't true.
 
g tsuji
Ranch Hand
Posts: 689
3
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
This is, of course - you say - once pointed out, I hope, erronous with the wrong package imported and this is the main cause of problems.

Also if you want to use consistently or sporadically the passed-in localName, you should add this.
 
Ulf Dittmer
Rancher
Posts: 42969
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
g tsuji wrote:


Good catch! Excellent example of the value of using the @Override annotation.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic