从JRuby调用Java方法抛出“无参数错误的构造函数” [英] Calling Java method from JRuby throws "no constructor for arguments error"

查看:257
本文介绍了从JRuby调用Java方法抛出“无参数错误的构造函数”的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我要尝试初始化来自jRuby的JaCop约束编程库中的类。我使用正确类型的参数,但由于某种原因,我不断收到此错误消息:

I'm trying to initialize this class from the JaCop constraint programming library from jRuby. I am using the correct type of arguments, but for some reason I keep getting this error message:

  NameError: no constructor for arguments
    (
      org.jruby.RubyArray,
      org.jruby.RubyArray,
      org.jruby.RubyArray,
      JaCoP.core.IntVar,
      JaCoP.core.IntVar)
    on Java::JaCoPConstraintsKnapsack::Knapsack
    (root) at rb/knapsack.rb:24

它指向的代码是:

k = Jacop::Knapsack.new(@values, @weights, quantity, knapsackCapacity, knapsackProfit)

Java类的签名构造函数是这样的:

The signature of the Java class constructor is this:

public Knapsack(int[] profits,
                int[] weights,
                IntVar[] quantity,
                IntVar knapsackCapacity,
                IntVar knapsackProfit)



<

I don't understand why jRuby complains that constructor is not found because it should be able to find this.

推荐答案

JRuby不能总是猜到复杂的方法,你可以尝试:

JRuby can not always guess "complicated" method args for you, you might want to try :


Jacop :: Knapsack.new(@values,@weights ,quantity.to_java(JaCoP.core.IntVar),knapsackCapacity,knapsackProfit)

$ c> int [] cast(不需要):

or even helping with the int[] cast (should not be necessary) :


Jacop :: Knapsack .new(@ values.to_java(:int),@ weights.to_java(:int),quantity.to_java(JaCoP.core.IntVar),knapsackCapacity,knapsackProfit)

这篇关于从JRuby调用Java方法抛出“无参数错误的构造函数”的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆