I’m developing an app with JWT (JWt, Java Web Toolkit — Emweb) using
Jruby
1.6.3.
I have a problem adding a listener taking one argument:
I define a signal with one argument [1]: @selection_clicked = Signal1.new(self)
and trigger it with one argument: @selection_clicked.trigger(WImage.new(resource, “chart
coming…”))
I then inspect the instance of the signal and I’m adding a listener:
puts @lists.selection_clicked.inspect # prints
#Java::EuWebtoolkitJwt::Signal1:0x69127c4d @lists.selection_clicked.add_listener(self) { |resource|
display_chart(resource) }
Below is the error I get, the null pointer exception being due to the
block
trying to access the argument.
The code works fine when using Listener1 and passing a block without
argument.
When using a Signal (with no argument), I have to modify the trigger
call
to remove the argument too, so the problem occurs when attaching the
listener.
Is my JRuby code to attach the listener correct?
Thanks in advance!
Raph
:1 warning: multiple values for a block parameter (0 for 1)
16191 [qtp555989664-18] ERROR eu.webtoolkit.jwt.WebSession - error
during
event handling: org.jruby.exceptions.RaiseException: Native Exception:
‘class java.lang.NullPointerException’; Message: null; StackTrace:
java.lang.NullPointerException
at
eu.webtoolkit.jwt.WContainerWidget.addWidget(WContainerWidget.java:304)
Looking at this again, looking for your input:
Can someone confirm that the following JRuby code is the right
translation
(regarding the addition of the event listener) of the java code below?
The
java code gets the listener’s argument, the Jruby listener gets no
argument
value (e is nil…).
Ruby:
nameEdit = WLineEdit.new
nameEdit.keyPressed.addListener(self) do |e|
puts ‘---------------------------’
puts e.getKey().toString()
puts ‘---------------------------’
end
Java:
nameEdit.keyPressed().addListener(this, new
Signal1.Listener() {
public void trigger(WKeyEvent e) {
greeting.setText("Key pressed : " +
e.getKey().toString());
}
});
I have tested again with this version of Jruby with the same result:
jruby 1.7.4 (1.9.3p392) 2013-05-16 2390d3b on OpenJDK 64-Bit Server VM
1.6.0_24-b24 [linux-amd64]
The output is:
17026 [qtp1272015198-18] ERROR eu.webtoolkit.jwt.WebSession - error
during
event handling: org.jruby.exceptions.RaiseException: (NoMethodError)
undefined method `getKey’ for nil:NilClass
Events on Swing works fine. I dont know how works on JWT but looks
similar. Maybe you aren’t doing reference to the right class as Karol
said. Some heritage can do a easy readable code for you …