Issue with Java constructor having variable-length arguments

I’m not sure if this issue is definitely related to what I stated in the
subject line. My specific problem is the following line of code doesn’t
work:

filter = javax.swing.filechooser.FileNameExtensionFilter.new(“Image
Files”,
“jpg”, “gif”)

This code gives the error:

Exception in thread “AWT-EventQueue-0” D:\rReport\lib\rb\jGUI.rb:67:in
`method_missing’: cannot load Java class
javax.swing.filefilter.FileNameExtensionFilter (NameError)

    from D:\rReport\lib\rb\jGUI.rb:67:in `initialize'
    from C:/Program

Files/jruby-1.1.3/lib/ruby/site_ruby/1.8/builtin/javasupport/core_ext/proc.rb:6:in
call' from C:/Program Files/jruby-1.1.3/lib/ruby/site_ruby/1.8/builtin/javasupport/core_ext/proc.rb:6:inmethod_missing’
from C:/Program
Files/jruby-1.1.3/lib/ruby/site_ruby/1.8/builtin/javasupport/proxy/interface.rb:174:in
`__jcreate_proxy!’
from :1
…internal jruby stack elided…

I think that it may be related to the fact that
FileNameExtensionFilter’s
constructor can take 2 or more strings, but I’m not entirely sure. Any
ideas
as to how I can get this code to work? Thanks!

View this message in context:
http://www.nabble.com/Issue-with-Java-constructor-having-variable-length-arguments-tp18737820p18737820.html
Sent from the JRuby - User mailing list archive at Nabble.com.


To unsubscribe from this list, please visit:

http://xircles.codehaus.org/manage_email

Sensual wrote:

`method_missing’: cannot load Java class
javax.swing.filefilter.FileNameExtensionFilter (NameError)

I get this error on Java 5 (because the class was added in Java 6, if I
were to guess). On Java 6, the error is different, but I can make it go
away by doing this:

filter = javax.swing.filechooser.FileNameExtensionFilter.new(“Image
Files”, [“jpg”, “gif”].to_java(:string))

HTH,
Matt


To unsubscribe from this list, please visit:

http://xircles.codehaus.org/manage_email

Matt B. wrote:

Exception in thread “AWT-EventQueue-0” D:\rReport\lib\rb\jGUI.rb:67:in
`method_missing’: cannot load Java class
javax.swing.filefilter.FileNameExtensionFilter (NameError)

I get this error on Java 5 (because the class was added in Java 6, if I
were to guess). On Java 6, the error is different, but I can make it go
away by doing this:

filter = javax.swing.filechooser.FileNameExtensionFilter.new(“Image
Files”, [“jpg”, “gif”].to_java(:string))

Yeah, there’s a bunch of TODOs littered around the Java integration tier
for varargs. The simplest way to do it right now is the code you showed,
just turning an arg list into an array. I’m hoping to fix that before
1.1.4.

  • Charlie

To unsubscribe from this list, please visit:

http://xircles.codehaus.org/manage_email

Perfect! Your code works nicely. Thanks :slight_smile:

Matt B.-2 wrote:

This code gives the error:
Files", [“jpg”, “gif”].to_java(:string))


View this message in context:
http://www.nabble.com/Issue-with-Java-constructor-having-variable-length-arguments-tp18737820p18740894.html
Sent from the JRuby - User mailing list archive at Nabble.com.


To unsubscribe from this list, please visit:

http://xircles.codehaus.org/manage_email

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs