Simple project with RSS not working (at least consistently)

140 views
Skip to first unread message

jen

unread,
May 30, 2014, 4:35:57 PM5/30/14
to rub...@googlegroups.com
After trying and succeeding setting up Ruboto, and a few apps provided as tutorials (a lot of fun so far), I am trying to do something short and simple: download a list of topics from an rss feed (xml file).
The ruby version is as follows:
require 'rss' # no need for open-uri
$subjects = []
rss = RSS::Parser.parse(url, false)
rss.items.each do |item|
subject = item.title.to_s
$subjects << subject
end
$subjects.each{ |s| puts s }
And I get:
Flamenco in Chinatown
How to do flamenco tango llamada or call
Practice for flamenco tango footwork
Flamenco/Middle Eatern Fusion
Storytelling: Stage Freight
Slow Flamenco Tango - Guitar Only
Practicing hand clapping for flamenco tango
Storytelling: How I learned to appreciate art
How to do flamenco tango llamada or call -Part 1
 
In Ruboto, I do:
E:\Ruboto>ruboto gen app --package org.ruboto.example.rss_0 --target android-17
Then I modify the script rss0_activity.rb to be:
require 'ruboto/widget'
require 'ruboto/util/toast'
require 'rss'
ruboto_import_widgets :Button, :LinearLayout, :TextView, :ListView

$subjects = []
#
# Collect list of items from RSS xml
# ----------------------------------
rss = RSS::Parser.parse(url)
rss.items.each do |item|
subject = item.title.to_s
$subjects << subject
end
#
# Display list of items
# ---------------------
class Rss0Activity
def onCreate(bundle)
    super
    set_title 'Download rss topics'
    self.content_view =
        linear_layout :orientation => :vertical do
          @list_view = list_view :list => []
        end
  end
def onResume
    super
    @list_view.adapter.add_all $subjects
  end
end

I have a simulator running.  I do 'rake install start', and the app sometimes works, but most of the time fails, and I can't figure out what is happening.  I have a rake log available for anyone interested, but I certainly don't have enough knowledge to make sense out of it.

I spent a lot of time on this, and the most frustrating is that I have seen this script work, and the list of topics displayed on the simulator, and just when I thought everything was fine, it stops working.

I will be grateful for any help.

Jen



jen

unread,
May 30, 2014, 11:53:08 PM5/30/14
to rub...@googlegroups.com
 I have a rake log available for anyone interested
The rake log is 500+ lines, but line 56 reports an exception.  Here are a few lines:
W/dalvikvm( 1830): VFY: unable to resolve exception class 1129 (Ljavax/management/InstanceAlreadyExistsException;)
W/dalvikvm( 1830): VFY: unable to find exception handler at addr 0xd
W/dalvikvm( 1830): VFY:  rejected Lorg/jruby/management/BeanManagerImpl;.register (Ljava/lang/String;Ljava/lang/Object;)V
W/dalvikvm( 1830): VFY:  rejecting opcode 0x0d at 0x000d
W/dalvikvm( 1830): VFY:  rejected Lorg/jruby/management/BeanManagerImpl;.register (Ljava/lang/String;Ljava/lang/Object;)V
W/dalvikvm( 1830): Verifier rejected class Lorg/jruby/management/BeanManagerImpl;
This app doesn't want to work any more.  Any suggestion will be greatly appreciated. 

Scott

unread,
May 31, 2014, 1:24:54 AM5/31/14
to rub...@googlegroups.com
Hi Jen,

I've been trying it in Ruboto IRB and can't seem to get it working. I'm not getting an error, just not getting anything back from RSS:Parser.parse.

I'll try the ruboto gen approach as soon as I get a chance.

One thing to note: You're hitting the internet, so Android requires you to include a permission in your manifest:

<uses-permission android:name='android.permission.INTERNET'/>

I seem to remember not getting very good error messages when that's missing. Also, another Android requirement, all access to the internet must be done from outside of the UI thread.

You may be doing all of this if it is working sometimes, but I thought I'd mention it just in case.

There are issues at times with some of the Ruby libraries. Some of them just require more stack space to parse than the normal thread allows. In those cases, you need to require 'ruboto/util/stack' to use a with_large_stack call to open up a secondary thread with more stack.

I'll try again soon.

jen

unread,
May 31, 2014, 8:53:33 AM5/31/14
to rub...@googlegroups.com
Hi Scott, thanks a lot for trying. 
I forgot to mention it, but I had included the internet permission in the manifest.
Now, I am adding at the top of the script:
require 'ruboto/util/stack'
with_large_stack{require 'rss'}
I assume this is the right way to require a larger stack. 
No better result so far.  I still get "Unfortunately, Rss0 has stopped" on the emulator.
Also, the log from 'rake log' (or 'adb logcat') doesn't contain the word 'stack'.

Scott

unread,
May 31, 2014, 11:56:17 AM5/31/14
to rub...@googlegroups.com
When I put the RSS::Parser.parse call inside the with_large_stack block (to force the remote call into another thread per Android requirements), I get an error trying to write to /tmp. I think need to feed the parse call the RSS XML instead of a URI to avoid this. 

I wont be able to test this for awhile...headed into a busy time.

jen

unread,
May 31, 2014, 12:54:04 PM5/31/14
to rub...@googlegroups.com
 I think need to feed the parse call the RSS XML instead of a URI to avoid this. 
How can I do that? 
I wont be able to test this for awhile...headed into a busy time.
 Got it.  Thanks for your comments, it's been helpful.

Jen

donV

unread,
Jun 1, 2014, 12:40:11 PM6/1/14
to rub...@googlegroups.com
Hi Jen!

If you put the project in a GitHub repository, I'll take a look at it and see if I can make it work.

Scott

unread,
Jun 1, 2014, 6:48:47 PM6/1/14
to rub...@googlegroups.com
I still haven't gotten it working. I have gotten beyond the /tmp directory problem. It seems that the /tmp dir is given from Dir.tmpdir (makes sense).

ENV['TMPDIR'] = <<context>>.files_dir.to_s

Solved the problem.

We should consider handling this in ruboto/base.rb (if we have access to the context) since Android isn't going to give the app access to /tmp.

jen

unread,
Jun 2, 2014, 8:44:20 AM6/2/14
to rub...@googlegroups.com
Hi DonV,

I just put the code in a GitHub repository:


Hope that works (First time user for GitHub.)

Thanks a lot for your help.

Jen

jen

unread,
Jun 2, 2014, 8:53:15 AM6/2/14
to rub...@googlegroups.com
Hi Scott,


ENV['TMPDIR'] = <<context>>.files_dir.to_s

Solved the problem.

We should consider handling this in ruboto/base.rb (if we have access to the context) since Android isn't going to give the app access to /tmp.

That is cryptic for me. Should I change my TMP env variable ?  (I am on Windows).

Scott Moyer

unread,
Jun 2, 2014, 10:32:53 AM6/2/14
to rub...@googlegroups.com
This is a change that needs to be made on your device or emulator in you script. The Ruby RSS code seems to be trying to store something in /tmp, and /tmp isn't available to you on an Android device. The main directory that is available to you is retrieved from your Android context (Activity) through the getFilesDir() call. It worked for me to assign that value (converted to a string) to ENV['TMPDIR']. 


--
You received this message because you are subscribed to the Google Groups "Ruboto (JRuby on Android)" group.
To unsubscribe from this group and stop receiving emails from it, send an email to ruboto+un...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

jen

unread,
Jun 2, 2014, 8:24:11 PM6/2/14
to rub...@googlegroups.com
I am scrutinizing my logs (rake log and adb logcat) to find references to the tmp directory.  It looks like the first part of the log doesn't have it, it only appears after I quit the logging process, so I am not sure about what is going on.  In any case, I will try to follow your suggestion. 
I am also trying the same thing with the gem 'simple-rss' with different issues.  I will use a separate post.

Uwe Kubosch

unread,
Jun 3, 2014, 3:18:27 AM6/3/14
to rub...@googlegroups.com
Hi @jen!

Ruboto master now includes setting the “java.io.tmpdir” system property which should be propagated to JRuby as well:

https://github.com/ruboto/ruboto/issues/628

Tempdir is used by “net/http” to store chunked streams, at least, and many other parts of the standard library and many gems.

If you can try master, it may help you, else wait for the next Ruboto release, sometime this month.
--
Uwe Kubosch
u...@kubosch.no
http://kubosch.no/




jen

unread,
Jun 3, 2014, 11:56:27 AM6/3/14
to rub...@googlegroups.com
Thanks Uwe, I'd love to try master, where do I get it?

donV

unread,
Jun 4, 2014, 3:31:08 PM6/4/14
to rub...@googlegroups.com
On Tuesday, June 3, 2014 5:56:27 PM UTC+2, jen wrote:
Thanks Uwe, I'd love to try master, where do I get it?

You need to clone the repository at https://github.com/ruboto/ruboto 


After checkout run "rake install" to build and install the Ruboto gem from the source.

jen

unread,
Jun 4, 2014, 4:02:48 PM6/4/14
to rub...@googlegroups.com
OK, I re-installed Ruboto, hoping to get the master with the new tmp issue corrected.  Not working.
Then I changed the rss url in my script, and replaced with:
All of a sudden,  SUCCESS!  I list all the titles from the rss on the emulator.  
I haven't yet investigated the issue, but a first difference is that the original url points to an xml file and the working one to an rss file.  After testing a few rss and xml, all the rss files work and the xml files fail so far.
The Ruby rss module (in a pure Ruby script) works well with either (and an RSS document is supposed to be an XML file). The difference only appears in a Ruboto script. 
Still, finally some progress.  Thanks to Use and Scott for their support.

jen

unread,
Jun 19, 2014, 7:54:54 PM6/19/14
to rub...@googlegroups.com
Not much progress so far.  My only conclusions at this point: 
  • the rss module works well in a pure ruby script to parse a wide variety of rss feeds, 
  • in the Ruboto context, it works for some rss feeds, and not for others.  There might be some correlation with the size of the rss feed (short feeds more likely to succeed), but not absolute.  And -- contrary to my initial guess -- there is no correlation with the feed extension (xml or rss).
My next steps: start from a simple rss feed that works, and add elements to it to determine what kind of content would cause Ruboto to hang.

jen

unread,
Jun 23, 2014, 7:09:19 PM6/23/14
to rub...@googlegroups.com
Finally, here is what I observe: all rss files can be parsed and displayed if their size is less than ~ 10KB.  The program fails for larger files.
The same occurs if I want to download a file using the ruby module 'open-uri'.  It works only for files < 10 KB.
I doesn't matter if I download in internal or external memory.
I don't have any idea about why this is happening.  I hope someone will be able to provide some light on the subject.
Thanks.

donV

unread,
Jun 24, 2014, 2:04:39 AM6/24/14
to rub...@googlegroups.com
Hi Jen!

I cloned your repository and am looking at the problem now.

How do you run your code?  The repository contains just the activity script.  Do you run it in a stand-alone Ruboto project or in Ruboto IRB?

Suller Andras

unread,
Jun 24, 2014, 6:36:44 AM6/24/14
to rub...@googlegroups.com

Hi jen,

Your email landed in the spam folder, maybe that's why you don't get answers.

The 10 KB size limit seems weird. It is way too small to get low memory errors, so the problem must be something else.
Did you try to wrap your code into a begin-rescue block to catch exceptions? Do you find anything in the logs if you search for "error" or "exception"?

Cheers,
Andras

jen

unread,
Jun 24, 2014, 7:53:00 AM6/24/14
to rub...@googlegroups.com
Hi DonV,

I run it in a standalone project, generally in the emulator.

jen

unread,
Jun 24, 2014, 8:03:27 AM6/24/14
to rub...@googlegroups.com
Hi Andras, 

When the process fails because the file is over 10K, here is an example of the lines I get in the rake log that contain the word 'exception':
Line 58
20140616 143443.372223 W/dalvikvm( 4356): VFY: unable to resolve exception class 1080 (Ljavax/management/InstanceAlreadyExistsException;)
20140616 143443.372223 W/dalvikvm( 4356): VFY: unable to find exception handler at addr 0xd
line 448
20140616 143455.975944 E/dalvikvm( 4356): Could not find class 'sun.misc.Signal', referenced from method jnr.posix.JavaPOSIX.signal
line 493
20140616 143455.987945 W/dalvikvm( 4356): threadid=10: thread exiting with uncaught exception (group=0xb3de5908)
20140616 143455.987945 E/AndroidRuntime( 4356): FATAL EXCEPTION: ScriptLoader for Java::OrgRubotoExampleRss_0::Rss0Activity
20140616 143455.987945 E/AndroidRuntime( 4356): org.jruby.embed.EvalFailedException: (ENOENT) No such file or directory - No such file or directory - /tmp
line 504
20140616 143455.989945 E/AndroidRuntime( 4356): Caused by: org.jruby.exceptions.RaiseException: (ENOENT) No such file or directory - No such file or directory - /tmp
But even when the file is small and the script works and displays the content, I get this exception:
line 63:
20140616 143258.054200 W/dalvikvm( 4282): VFY: unable to resolve exception class 1080 (Ljavax/management/InstanceAlreadyExistsException;)
20140616 143258.054200 W/dalvikvm( 4282): VFY: unable to find exception handler at addr 0xd

jen

unread,
Jun 24, 2014, 10:39:26 AM6/24/14
to rub...@googlegroups.com
Note: I have created and tested a lot of rss files posted on a home network webpage in order to understand why some files worked and others didn't.  
To help reproducing the problem, here is a public webpage with a file that works (8.43 KB):
and another that doesn't work (13.1 KB):
Thanks for the advice.

Suller Andras

unread,
Jun 25, 2014, 6:36:11 AM6/25/14
to rub...@googlegroups.com

Hi jen,

I think the root of the problem is described in this line:

>> 20140616 143455.989945 E/AndroidRuntime( 4356): Caused by: org.jruby.exceptions.RaiseException: (ENOENT) No such file or directory - No such file or directory - /tmp

Maybe it tries to download the RSS into a temporary file but there is no /tmp folder. Try to configure the TEMP folder in Ruboto. As far as I remember there was a recent discussion about how to do it on this mailing list.

Regards,
Andras

jen

unread,
Jun 25, 2014, 7:27:13 PM6/25/14
to rub...@googlegroups.com
Hi Andras,  indeed, it looks like there is still a  /tmp folder issue.  This had been spotted by Scott at the beginning, and a fix had been proposed by donV in:
I believe I am using the last version of Ruboto that incorporates that fix (I cloned it from GitHub yesterday), but apparently the issue is still there. In addition, I am not clear why there is a /tmp issue with files > 10KB, and not with smaller files !

@donV, did you have a chance to take another look at this?

Thanks.

donV

unread,
Jul 19, 2014, 8:37:56 AM7/19/14
to rub...@googlegroups.com
On Thursday, June 26, 2014 1:27:13 AM UTC+2, jen wrote:
Hi Andras,  indeed, it looks like there is still a  /tmp folder issue.  This had been spotted by Scott at the beginning, and a fix had been proposed by donV in:
I believe I am using the last version of Ruboto that incorporates that fix (I cloned it from GitHub yesterday), but apparently the issue is still there. In addition, I am not clear why there is a /tmp issue with files > 10KB, and not with smaller files !

@donV, did you have a chance to take another look at this?


Looking at it now.  Could you give me push access to the repo?  Then I can push changes to display what works. 

jen

unread,
Jul 20, 2014, 12:10:35 PM7/20/14
to rub...@googlegroups.com
Done.  Let me know if there is an issue.

donV

unread,
Jul 27, 2014, 6:55:44 PM7/27/14
to rub...@googlegroups.com
OK, got something working.  The "/tmp" issue is fixed in JRuby 1.7.14, and I am adding a test to Ruboto to verify it for the future.


However, when I run the RSS test, I get the following error:

Exception: value <Mon, 20 August 2011 22:32:57 +0100> of tag <lastBuildDate> is not available.

/data/app/org.ruboto.test_app-2.apk!/jruby.home/lib/ruby/1.9/rss/0.9.rb:107:in `lastBuildDate='

/data/app/org.ruboto.test_app-2.apk!/jruby.home/lib/ruby/1.9/rss/parser.rb:456:in `start_get_text_element'

org/jruby/RubyProc.java:271:in `call'

/data/app/org.ruboto.test_app-2.apk!/jruby.home/lib/ruby/1.9/rss/parser.rb:358:in `tag_end'

/data/app/org.ruboto.test_app-2.apk!/jruby.home/lib/ruby/1.9/rexml/parsers/streamparser.rb:26:in `parse'

/data/app/org.ruboto.test_app-2.apk!/jruby.home/lib/ruby/1.9/rexml/document.rb:205:in `parse_stream'

/data/app/org.ruboto.test_app-2.apk!/jruby.home/lib/ruby/1.9/rss/rexmlparser.rb:22:in `_parse'

/data/app/org.ruboto.test_app-2.apk!/jruby.home/lib/ruby/1.9/rss/parser.rb:164:in `parse'

/data/app/org.ruboto.test_app-2.apk!/jruby.home/lib/ruby/1.9/rss/parser.rb:79:in `parse'



Luckily, I get the same error running the same code in Ruby 2.1.2 IRB :)  so I think it is correct to get the error :)


@jen, could you give me an example of code that works for you in IRB?


jen

unread,
Jul 29, 2014, 9:17:03 AM7/29/14
to rub...@googlegroups.com
DonV, sorry this link seems bad, I get the same error.  I should have checked that :(  
But this is working for me in IRB:


What is the best place to get JRuby 1.7.14?  The last official one seems to be 1.7.13.

Uwe Kubosch

unread,
Oct 13, 2014, 3:33:50 PM10/13/14
to rub...@googlegroups.com
Hi @jen!

I have now added tests for this in Ruboto 1.2.0 and you can use the latest releases of JRuby.

To test RSS I use this URL:

http://www.feedforall.com/sample.xml
Reply all
Reply to author
Forward
0 new messages