0

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.

1 Answer 1

3

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)

Sign up to request clarification or add additional context in comments.

1 Comment

You were absolutely right. I had to cast the ints as well to make it work.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.