Author Topic: [Java][Android]Issues with making a RSS Dom Parser  (Read 6220 times)

0 Members and 1 Guest are viewing this topic.

Offline Eeems

  • Mr. Dictator
  • Administrator
  • LV13 Extreme Addict (Next: 9001)
  • *************
  • Posts: 6268
  • Rating: +318/-36
  • little oof
    • View Profile
    • Eeems
[Java][Android]Issues with making a RSS Dom Parser
« on: November 07, 2011, 08:50:00 pm »
Error Log: http://pastebin.com/YaP28L19
Code in question: http://pastebin.com/sDYgwB5B (line 56, called from line 43)
Full source code: http://dl.dropbox.com/u/763272/android/Omnimaga.zip
I'm thinking it's the fact that (Node)list.item(i) is returning a null. No idea if that is the problem though. Anybody have a fix/better way to do this?
( I've tried using SAX to parse the xml, but it keeps on not working ( returning a blank feed ) ).
« Last Edit: November 07, 2011, 08:50:33 pm by Eeems »
/e

Offline jacobly

  • LV5 Advanced (Next: 300)
  • *****
  • Posts: 205
  • Rating: +161/-1
    • View Profile
Re: [Java][Android]Issues with making a RSS Dom Parser
« Reply #1 on: November 07, 2011, 11:29:10 pm »
Actually, list.item(i) is not returning null, but list.item(i).getNodeValue() is. According to the table at the top of this page, the nodeValue of an instance of Element is always null. Anyway, I will try to see if I can get SAX to work.

Offline DJ Omnimaga

  • Clacualters are teh gr33t
  • CoT Emeritus
  • LV15 Omnimagician (Next: --)
  • *
  • Posts: 55943
  • Rating: +3154/-232
  • CodeWalrus founder & retired Omnimaga founder
    • View Profile
    • Dream of Omnimaga Music
Re: [Java][Android]Issues with making a RSS Dom Parser
« Reply #2 on: November 08, 2011, 01:28:34 am »
SAX as in Cemetech's shoutbox? I'M confused here ???

Offline jacobly

  • LV5 Advanced (Next: 300)
  • *****
  • Posts: 205
  • Rating: +161/-1
    • View Profile
Re: [Java][Android]Issues with making a RSS Dom Parser
« Reply #3 on: November 08, 2011, 01:41:39 am »
SAX as in Simple API for XML. :)

Offline DJ Omnimaga

  • Clacualters are teh gr33t
  • CoT Emeritus
  • LV15 Omnimagician (Next: --)
  • *
  • Posts: 55943
  • Rating: +3154/-232
  • CodeWalrus founder & retired Omnimaga founder
    • View Profile
    • Dream of Omnimaga Music
Re: [Java][Android]Issues with making a RSS Dom Parser
« Reply #4 on: November 08, 2011, 01:44:10 am »
Oh ok, I got confused there. I was wondering if Eeems was writing something for Cemetech that allows people to use SAX from a mobile device or something (like the TI-Planet app on iDevices). SAX is the acronym of their shoutbox, hence the confusion ;D

Offline jacobly

  • LV5 Advanced (Next: 300)
  • *****
  • Posts: 205
  • Rating: +161/-1
    • View Profile
Re: [Java][Android]Issues with making a RSS Dom Parser
« Reply #5 on: November 08, 2011, 02:20:51 am »
Cool, it works. I created an RSS parser that uses SAX, then I uncommented your code and made a few minor changes, and it works!
Anyway, I'll edit when I get it uploaded.

Edit: http://jacob.heliohost.org/Omnimaga.zip
« Last Edit: November 08, 2011, 03:11:18 am by jacobly »

Offline Eeems

  • Mr. Dictator
  • Administrator
  • LV13 Extreme Addict (Next: 9001)
  • *************
  • Posts: 6268
  • Rating: +318/-36
  • little oof
    • View Profile
    • Eeems
Re: [Java][Android]Issues with making a RSS Dom Parser
« Reply #6 on: November 08, 2011, 03:41:10 am »
Thanks! Ill test it out when I get home from work.

EDIT: Alright just about to test now. You just had to change my source file setup didn't you ;P

EDIT2: Alright it works, although clicking on an item doesn't give more info, it crashes. Thanks a ton though!
« Last Edit: November 08, 2011, 09:20:22 am by Eeems »
/e

Offline jacobly

  • LV5 Advanced (Next: 300)
  • *****
  • Posts: 205
  • Rating: +161/-1
    • View Profile
Re: [Java][Android]Issues with making a RSS Dom Parser
« Reply #7 on: November 08, 2011, 10:43:59 am »
Feel free to change the packages back. I rewrote the RSS Parser like 4 times, and each time I moved it to a new package instead of deleting the old code. :P
Also, the more info page works fine for me. What version of Android are you testing it on?

Offline Eeems

  • Mr. Dictator
  • Administrator
  • LV13 Extreme Addict (Next: 9001)
  • *************
  • Posts: 6268
  • Rating: +318/-36
  • little oof
    • View Profile
    • Eeems
Re: [Java][Android]Issues with making a RSS Dom Parser
« Reply #8 on: November 08, 2011, 05:51:52 pm »
2.3.7 ( CyanogenMod 7 )
It's giving me an error on startActivityForResult(itemintent,0);
Logcat of the error:
Quote
11-08 08:25:42.359: E/AndroidRuntime(18774): FATAL EXCEPTION: main
11-08 08:25:42.359: E/AndroidRuntime(18774): android.content.ActivityNotFoundException: Unable to find explicit activity class {org.omnimaga.eeems/org.omnimaga.eeems.ShowDescription}; have you declared this activity in your AndroidManifest.xml?
11-08 08:25:42.359: E/AndroidRuntime(18774):    at android.app.Instrumentation.checkStartActivityResult(Instrumentation.java:1405)
11-08 08:25:42.359: E/AndroidRuntime(18774):    at android.app.Instrumentation.execStartActivity(Instrumentation.java:1379)
11-08 08:25:42.359: E/AndroidRuntime(18774):    at android.app.Activity.startActivityForResult(Activity.java:2827)
11-08 08:25:42.359: E/AndroidRuntime(18774):    at org.omnimaga.eeems.OmnimagaActivity.onItemClick(OmnimagaActivity.java:61)
11-08 08:25:42.359: E/AndroidRuntime(18774):    at android.widget.AdapterView.performItemClick(AdapterView.java:284)
11-08 08:25:42.359: E/AndroidRuntime(18774):    at android.widget.ListView.performItemClick(ListView.java:3513)
11-08 08:25:42.359: E/AndroidRuntime(18774):    at android.widget.AbsListView$PerformClick.run(AbsListView.java:1849)
11-08 08:25:42.359: E/AndroidRuntime(18774):    at android.os.Handler.handleCallback(Handler.java:587)
11-08 08:25:42.359: E/AndroidRuntime(18774):    at android.os.Handler.dispatchMessage(Handler.java:92)
11-08 08:25:42.359: E/AndroidRuntime(18774):    at android.os.Looper.loop(Looper.java:130)
11-08 08:25:42.359: E/AndroidRuntime(18774):    at android.app.ActivityThread.main(ActivityThread.java:3835)
11-08 08:25:42.359: E/AndroidRuntime(18774):    at java.lang.reflect.Method.invokeNative(Native Method)
11-08 08:25:42.359: E/AndroidRuntime(18774):    at java.lang.reflect.Method.invoke(Method.java:507)
11-08 08:25:42.359: E/AndroidRuntime(18774):    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:847)
11-08 08:25:42.359: E/AndroidRuntime(18774):    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:605)
11-08 08:25:42.359: E/AndroidRuntime(18774):    at dalvik.system.NativeStart.main(Native Method)
/e

Offline Binder News

  • LV8 Addict (Next: 1000)
  • ********
  • Posts: 785
  • Rating: +46/-3
  • Zombie of Tomorrow
    • View Profile
Re: [Java][Android]Issues with making a RSS Dom Parser
« Reply #9 on: November 08, 2011, 06:54:08 pm »
It appears, according to the error, that you need to declare that class as an activity in your AndroidManifest.xml file. Also, does the ShowDescription class extend Activity?
Spoiler For userbars:







Hacker-in-training!   Z80 Assembly Programmer     Axe Programmer
C++ H4X0R             Java Coder                           I <3 Python!

Perdidisti ludum     Cerebrum non habes

"We are humans first, no matter what."
"Fame is a vapor, popularity an accident, and riches take wings. Only one thing endures, and that is character."
Spoiler For Test Results:





Offline Eeems

  • Mr. Dictator
  • Administrator
  • LV13 Extreme Addict (Next: 9001)
  • *************
  • Posts: 6268
  • Rating: +318/-36
  • little oof
    • View Profile
    • Eeems
Re: [Java][Android]Issues with making a RSS Dom Parser
« Reply #10 on: November 10, 2011, 09:34:50 am »
It appears, according to the error, that you need to declare that class as an activity in your AndroidManifest.xml file. Also, does the ShowDescription class extend Activity?
Oh lol, I just copied over the source files, didn't think about AndroidManifest.xml
ShowDescrition should extend it I think, check out the zip.
/e

Offline Eeems

  • Mr. Dictator
  • Administrator
  • LV13 Extreme Addict (Next: 9001)
  • *************
  • Posts: 6268
  • Rating: +318/-36
  • little oof
    • View Profile
    • Eeems
Re: [Java][Android]Issues with making a RSS Dom Parser
« Reply #11 on: November 10, 2011, 07:55:02 pm »
Alright, I got it to work now, I do have an issue though, but it has nothing to do with the code really.
The first time you try to access Omnimaga from anywhere it take a really long time to access, apparently longer then SAXParser's timeout is so it's impossible to connect to the Omnimaga RSS. I can't seem to figure out a way to extend the timeout of SAXParser so if anybody knows how that would be helpful. I've also contacted Netham45 about figuring out why this is happening.

( Yes I know this is a doublepost :P )
« Last Edit: November 10, 2011, 07:55:18 pm by Eeems »
/e

Offline jacobly

  • LV5 Advanced (Next: 300)
  • *****
  • Posts: 205
  • Rating: +161/-1
    • View Profile
Re: [Java][Android]Issues with making a RSS Dom Parser
« Reply #12 on: November 10, 2011, 09:21:48 pm »
SAXParser in a very round-about way eventually uses a URLConnection, so you might as well create your own and set its timeout.
Code: [Select]
public RSS(String uri) {
try {
SAXParser parser = SAXParserFactory.newInstance().newSAXParser();
URL url = new URL(uri);
URLConnection conn = url.openConnection();
conn.setConnectTimeout(0);
conn.setReadTimeout(0);
parser.parse(conn.getInputStream(), new RSSHandler());
} catch (SAXException ex) {
ex.printStackTrace();
} catch (MalformedURLException ex) {
ex.printStackTrace();
} catch (IOException ex) {
ex.printStackTrace();
} catch (ParserConfigurationException ex) {
ex.printStackTrace();
}
}

Offline Eeems

  • Mr. Dictator
  • Administrator
  • LV13 Extreme Addict (Next: 9001)
  • *************
  • Posts: 6268
  • Rating: +318/-36
  • little oof
    • View Profile
    • Eeems
Re: [Java][Android]Issues with making a RSS Dom Parser
« Reply #13 on: November 10, 2011, 09:45:02 pm »
SAXParser in a very round-about way eventually uses a URLConnection, so you might as well create your own and set its timeout.
Code: [Select]
public RSS(String uri) {
try {
SAXParser parser = SAXParserFactory.newInstance().newSAXParser();
URL url = new URL(uri);
URLConnection conn = url.openConnection();
conn.setConnectTimeout(0);
conn.setReadTimeout(0);
parser.parse(conn.getInputStream(), new RSSHandler());
} catch (SAXException ex) {
ex.printStackTrace();
} catch (MalformedURLException ex) {
ex.printStackTrace();
} catch (IOException ex) {
ex.printStackTrace();
} catch (ParserConfigurationException ex) {
ex.printStackTrace();
}
}
Alright thanks, I'll try that when I get home tomorrow morning from work ( leaving now )
/e