Omnimaga

General Discussion => Technology and Development => Computer Programming => Topic started by: Eeems on November 07, 2011, 08:50:00 pm

Title: [Java][Android]Issues with making a RSS Dom Parser
Post by: Eeems 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 ) ).
Title: Re: [Java][Android]Issues with making a RSS Dom Parser
Post by: jacobly 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 (http://developer.android.com/reference/org/w3c/dom/Node.html) page, the nodeValue of an instance of Element is always null. Anyway, I will try to see if I can get SAX to work.
Title: Re: [Java][Android]Issues with making a RSS Dom Parser
Post by: DJ Omnimaga on November 08, 2011, 01:28:34 am
SAX as in Cemetech's shoutbox? I'M confused here ???
Title: Re: [Java][Android]Issues with making a RSS Dom Parser
Post by: jacobly on November 08, 2011, 01:41:39 am
SAX as in Simple API for XML. :)
Title: Re: [Java][Android]Issues with making a RSS Dom Parser
Post by: DJ Omnimaga 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
Title: Re: [Java][Android]Issues with making a RSS Dom Parser
Post by: jacobly 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 (http://jacob.heliohost.org/Omnimaga.zip)
Title: Re: [Java][Android]Issues with making a RSS Dom Parser
Post by: Eeems 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!
Title: Re: [Java][Android]Issues with making a RSS Dom Parser
Post by: jacobly 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?
Title: Re: [Java][Android]Issues with making a RSS Dom Parser
Post by: Eeems 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)
Title: Re: [Java][Android]Issues with making a RSS Dom Parser
Post by: Binder News 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?
Title: Re: [Java][Android]Issues with making a RSS Dom Parser
Post by: Eeems 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.
Title: Re: [Java][Android]Issues with making a RSS Dom Parser
Post by: Eeems 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 )
Title: Re: [Java][Android]Issues with making a RSS Dom Parser
Post by: jacobly 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();
}
}
Title: Re: [Java][Android]Issues with making a RSS Dom Parser
Post by: Eeems 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 )