*****/jruby-1.4.0/lib/ruby/site_ruby/shared/builtin/javasupport/java.rb:5
0:in `method_missing': wrong number of arguments (1 for 0)
(ArgumentError)
from step1.rb:2
JRuby and Java version:
*****>jruby -v
jruby 1.4.0 (ruby 1.8.7 patchlevel 174) (2009-11-02 69fbfa3) (Java
HotSpot(TM) C
lient VM 1.6.0_16) [x86-java]
after some other changes in the code I finally got it running. The
following errors are in the code, too:
class Click < java.awt.event.ActionListener
This does not work, because ActionListener is an interface which cannot
be subclassed. Deleting “< java.awt.event.Actionlistener” solves the
problem. Implementing an interface in JRuby does not really make sense,
does it?
java.lang.Object source = event.getSource()
This throws the same Exception like “java.lang.boolean $_clickMeMode =
true”. Deleting “java.lang.Object” fixes this problem.
after some other changes in the code I finally got it running. The
following errors are in the code, too:
class Click < java.awt.event.ActionListener
This does not work, because ActionListener is an interface which cannot
be subclassed. Deleting “< java.awt.event.Actionlistener” solves the
problem. Implementing an interface in JRuby does not really make sense,
does it?
It sure makes sense if you want to pass instances to Java methods. You
implement Java interfaces in JRuby using the “include” method in the
class:
class Click
include java.awt.event.ActionListener
…
end
yes, I have read this solution. But in Ruby the addActionListener method
of the Button does not require an instance of ActionListener, in Java it
does. Why doesn’t the method call
$_button.addActionListener(Click.new()) raise an exception if
Click.new() is no instance of ActionListener?
after some other changes in the code I finally got it running. The
following errors are in the code, too:
class Click < java.awt.event.ActionListener
This does not work, because ActionListener is an interface which cannot
be subclassed. Deleting “< java.awt.event.Actionlistener” solves the
problem. Implementing an interface in JRuby does not really make sense,
does it?
It sure makes sense if you want to pass instances to Java methods. You
implement Java interfaces in JRuby using the “include” method in the
class:
yes, I have read this solution. But in Ruby the addActionListener method
of the Button does not require an instance of ActionListener, in Java it
does. Why doesn’t the method call
$_button.addActionListener(Click.new()) raise an exception if
Click.new() is no instance of ActionListener?
JRuby generally tries to do what you tell it when it comes to methods
that take an interface argument. Here, we will provide a wrapper
ActionListener implementation for the Click object so that the method
call can succeed. If that’s not what you want, you should write the
code differently
yes, I have read this solution. But in Ruby the addActionListener method
of the Button does not require an instance of ActionListener, in Java it
does. Why doesn’t the method call
$_button.addActionListener(Click.new()) raise an exception if
Click.new() is no instance of ActionListener?
JRuby generally tries to do what you tell it when it comes to methods
that take an interface argument. Here, we will provide a wrapper
ActionListener implementation for the Click object so that the method
call can succeed. If that’s not what you want, you should write the
code differently
Charlie
Thanks for that answer. I am just curious and wanted to know why it
works.
This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.