Hi Developers,

I have used the simple utility jrubyc that compiles a .rb file into .java. When I try to
run the resulting .class file, I got got an exception:

A very simple jruby file is used to declare a class. Then, I write a main method inside the generated java code in order to instantiate an object and call method. Here is a code snippet:

#myruby.rb
class MyRubyClass
  def helloWorld
    puts "Hello from Ruby"
  end
end

$ jrubyc --java myruby.rb
javac -d /Users/anabhan/Work/Workspace/JavaRuby -cp /Users/anabhan/.rvm/rubies/jruby-head/lib/jruby.jar:. MyRubyClass.java

$ java  -cp /.rvm/rubies/jruby-head/lib/jruby.jar:.  MyRubyClass

Exception in thread "main" java.lang.ExceptionInInitializerError
Caused by: java.lang.NullPointerException
        at MyRubyClass.<clinit>(MyRubyClass.java:18)


12:  private static final Ruby __ruby__ = Ruby.getGlobalRuntime();
13:  private static final RubyClass __metaclass__;
14:
15: static {
16:
17:    RubyClass metaclass = __ruby__.getClass("MyRubyClass");
18:    metaclass.setClassAllocator(MyRubyClass.class);
19: if (metaclass == null) throw new NoClassDefFoundError("Could not load Ruby
20:     class: MyRubyClass");
21:    __metaclass__ = metaclass;
22:  }

The problem is that the __ruby__.getClass("MyRubyClass") returns null. I checked that the method Ruby.getGlobalRuntime() returns a not-null object.

Any idea about what is going wrong?

Thank you,
Ahmed Nabhan



---------------------------------------------------------------------
To unsubscribe from this list, please visit:

   http://xircles.codehaus.org/manage_email


Reply via email to