Forum: JRuby JRuby File Ops

Posted by Gary Hasson (gary2594)
on 2011-07-23 21:25
Attachment: gui_filetest.rb (3,11 KB)
Attachment: filetest.rb (807 Bytes)
File operations that work in my simple JRuby program do not work in my
Swing GUI based program. The attached file "filetest.rb" reads in a text
file (itself) and sends it to the console with a "puts".

That code was copied into the other attachment "gui_filetest.rb", which
should do the same thing when triggered by my popup menu selection.

The line that causes the error follows:
#      read_from_disk # This causes an error
The error message is at the very bottom of the file,
 between =begin and =end.
Posted by Gary Hasson (gary2594)
on 2011-07-24 19:59
I found the problem, so don't bother with this.
Thanks,
Gary
Posted by Charles Nutter (headius)
on 2011-07-25 03:35
(Received via mailing list)
Sorry nobody got back to you. What was the problem?

- Charlie
Posted by Gary Hasson (gary2594)
on 2011-07-25 13:31
Hi Charles,
The problem was a simple Ruby mistake that I made. However, the error 
message mentioned something relative to Java, so I thought that somehow 
my Ruby file-related commands were somehow clashing with Java. After a 
while, I stopped looking for Java-related issues, and then finally saw 
that it was just a simple Ruby variable-scope issue.

I had been so focused on the new aspects of Java and Swing, that I got 
sloppy with Ruby.

Regards,
Gary
Posted by Charles Nutter (headius)
on 2011-07-25 21:53
(Received via mailing list)
Ok, it sounds like you may have gotten a Java error. Can you show me?
If it's a Java error/exception, that's almost always a bug; we should
be re-throwing a Ruby exception with an appropriate message. If it is
a Ruby exception but has a bad Java-related error message, that's
something we'd want to fix too.

- Charlie
Posted by Gary Hasson (gary2594)
on 2011-07-25 22:03
Charlie,
Here is the error msg:
Exception in thread "AWT-EventQueue-0"
org.jruby.exceptions.RaiseException: (TypeError) can't convert nil into
String
  at org.jruby.RubyFileTest.exist?(org/jruby/RubyFileTest.java:129)
  at TextStatus.read_from_disk(./gui_filetest.rb:30)
  at TextStatus.create_popup(./gui_filetest.rb:47)
  at org.jruby.RubyProc.call(org/jruby/RubyProc.java:268)
  at org.jruby.RubyProc.call(org/jruby/RubyProc.java:232)

When I looked at the error, I saw the ".java" in the error msg and
thought that perhaps Java had something to do with it. However, the
error was that my filename variable was not readable within the scope of
the class. Once I corrected that, it all worked. So Java had nothing to
do with it.
Regards,
Gary
Posted by Charles Nutter (headius)
on 2011-07-25 22:10
(Received via mailing list)
Ahh I see...so the issue here is that we're raising an appropriate
Ruby error, but it is eventually handled by the Java logic in the AWT
event thread. The .java files in the trace are to show the core class
methods, which are mostly implemented in Java in JRuby.

In any case, I believe this is being handled correctly by JRuby, and
it's just an interaction issue with AWT that presented it in an odd
way.

Thank you!

- Charlie
Posted by Shobha V. (shobha_v)
on 2012-05-09 13:25
How to get full file path when trying to upload csv file.

Regards,
Shobha
Please log in before posting. Registration is free and takes only a minute.
Existing account (Switch to SSL-encrypted connection)
NEW: Do you have a Google/GoogleMail or Yahoo account? No registration required!
Log in with Google account | Log in with Yahoo account
No account? Register here.