Can't extend Java class from JRuby

Hi -

This is stupid, but it’s baffling the hell out of me. I have a Java
class:

package javatest;

public class Test {
public void sayHi() { System.out.println(“Hello.”); }
}


And I have a JRuby file:

require ‘java’
include_class ‘javatest.Test’

This works.

jt = Test.new
jt.sayHi

This works

class MyList < java.util.ArrayList
def say_hi
puts “hi”
end
end
ml = MyList.new
ml.say_hi

This works too! Re-opening javatest.Test

class Test
def sayOuch
puts “Ouch!”
end
end

t = Test.new
t.sayHi
t.sayOuch

So why doesn’t this work?!

class ExtendedClass < Test
def sayOuch
puts “Ouch!”
end
end
ec = ExtendedClass.new
ec.sayOuch


Here’s (part of) the error:

JavaProxyClassFactory.java:779:in
org.jruby.javasupport.proxy.JavaProxyClassFactory.validateArgs': java.lang.IllegalArgumentException: cannor add classes to package javatest (NativeException) from JavaProxyClassFactory.java:163:inorg.jruby.javasupport.proxy.JavaProxyClassFactory.newProxyClass’
from JavaProxyClass.java:111:in
org.jruby.javasupport.proxy.JavaProxyClass.getProxyClass' from JavaProxyClass.java:662:inorg.jruby.javasupport.proxy.JavaProxyClass.get_with_class’
from null:-1:in
org.jruby.javasupport.proxy.JavaProxyClassInvoker$get_with_class_FS1.call' from FastInvocationCallback.java:55:inorg.jruby.runtime.callback.FastInvocationCallback.execute’
from SimpleCallbackMethod.java:70:in
org.jruby.internal.runtime.methods.SimpleCallbackMethod.call' from CallSite.java:153:inorg.jruby.runtime.CallSite$ICNonBlockCallSite.call’
from CallSite.java:100:in
`org.jruby.runtime.CallSite$ArgumentBoxingCallSite.call’
… 47 levels…


I’m using JRuby 1.1rc, Leopard w/ Java 1.5. I’m really baffled here -
I’ve tried to find an answer, but have come up with nothing. What am I
doing wrong?

Help is appreciated.

Thanks,

Shane

I am an idiot:

package javatest;

public class Test {
public void sayHi() { System.out.println(“Hello.”); }
}

The problem is that “javatest” is apparently already a package, and the
kind of package you can’t extend, or something. Anyway, if you change
that package name to something that doesn’t conflict, it’s ok.

Shane

Shane Hoversten wrote:

package javatest;

public class Test {
public void sayHi() { System.out.println(“Hello.”); }
}

This works

class MyList < java.util.ArrayList

So why doesn’t this work?!

class ExtendedClass < Test

Hi Shane,

I’m taking a wild shot in the dark here, as I’m at minute 2 of my
learning of JRuby, but shouldn’t you use the whole name (with the
package) for your own class as you did for ArrayList? i.e. “class
ExtendedClass < javatest.Test”

Hope it helps!

/ph