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
The code that it points to is this:
k = Jacop::Knapsack.new(@values, @weights, quantity, knapsackCapacity, knapsackProfit)
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 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)
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)