Java.lang.boolean error

Hello,

I just started to learn JRuby. So I installed
“jruby_windowsjre_1_4_0.exe” on my windows xp professional machine.

I wanted to start with these examples:

and I found the following error implementing the form example. I reduced
the code such that the following two lines give the following error
message:

The Code:

require 'java'
java.lang.boolean $_clickMeMode = true

The Error:

*****/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]

So, why does this simple code not work?

Thanks for any help

KungFuZius

That looks like you are trying to do some kind of mix between java an
ruby?

try:

click_me_mode = true

Thats it. Its ruby. Embrace it!

:smiley:

On Sun, Mar 14, 2010 at 12:28 AM, Some O. [email protected] wrote:

message:
*****/jruby-1.4.0/lib/ruby/site_ruby/shared/builtin/javasupport/java.rb:5
HotSpot™ C
Posted via http://www.ruby-forum.com/.


To unsubscribe from this list, please visit:

  http://xircles.codehaus.org/manage_email


To unsubscribe from this list, please visit:

http://xircles.codehaus.org/manage_email

Hi,

tanks for the fast answer. If it is as simple, why does the example use
java.lang.boolean?

Kind regards
KungFuZius

Albert R. wrote:

What example?

On Sun, Mar 14, 2010 at 12:54 AM, Some O. [email protected] wrote:


To unsubscribe from this list, please visit:

  http://xircles.codehaus.org/manage_email


To unsubscribe from this list, please visit:

http://xircles.codehaus.org/manage_email

this one, the first example with java gui:

On Sun, Mar 14, 2010 at 10:22 AM, Some O. [email protected] wrote:

this one, the first example with java gui:
Oracle Java Technologies | Oracle

Looks like an error in the article. In (J)Ruby, the type of variable
is never defined like this.

Thanks,
–Vladimir


To unsubscribe from this list, please visit:

http://xircles.codehaus.org/manage_email

What example?

On Sun, Mar 14, 2010 at 12:54 AM, Some O. [email protected] wrote:


To unsubscribe from this list, please visit:

  http://xircles.codehaus.org/manage_email


To unsubscribe from this list, please visit:

http://xircles.codehaus.org/manage_email

Vladimir S. wrote:

On Sun, Mar 14, 2010 at 10:22 AM, Some O. [email protected] wrote:

this one, the first example with java gui:
Oracle Java Technologies | Oracle

Looks like an error in the article. In (J)Ruby, the type of variable
is never defined like this.

thanks, then I will report that issue to the editor of the article.

Hello again,

after some other changes in the code I finally got it running. The
following errors are in the code, too:

  1. 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?

  2. java.lang.Object source = event.getSource()
    This throws the same Exception like “java.lang.boolean $_clickMeMode =
    true”. Deleting “java.lang.Object” fixes this problem.

Thank you for your help.

Uwe K. wrote:

On Mar 14, 2010, at 12:56 PM, Some O. wrote:

Hello again,

after some other changes in the code I finally got it running. The
following errors are in the code, too:

  1. 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?

On Mar 14, 2010, at 12:56 PM, Some O. wrote:

Hello again,

after some other changes in the code I finally got it running. The
following errors are in the code, too:

  1. 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


With kind regards
Uwe K.
Kubosch Consulting
[email protected]


To unsubscribe from this list, please visit:

http://xircles.codehaus.org/manage_email

On Sun, Mar 14, 2010 at 6:51 PM, Some O. [email protected] wrote:

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 :slight_smile:

  • Charlie

To unsubscribe from this list, please visit:

http://xircles.codehaus.org/manage_email

Charles Nutter wrote:

On Sun, Mar 14, 2010 at 6:51 PM, Some O. [email protected] wrote:

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 :slight_smile:

  • Charlie

Thanks for that answer. I am just curious and wanted to know why it
works.