如何在java中返回多个值?

时间:2016-03-23 21:44:28

标签: java java-native-interface return

我编写了我的代码,我希望在:

中返回多个值
public int[] getResult(){
return geneticAlgorithm(cost,profit,gens,turns,cmax);

但是当我用这个时让我看错:

Exception in thread "AWT-EventQueue-0" java.lang.UnsatisfiedLinkError: knapsacproject.algorithm.geneticAlgorithm([I[IIII)[I
at knapsacproject.algorithm.geneticAlgorithm(Native Method)
at knapsacproject.algorithm.getResult(algorithm.java:39)

我的代码:

 package knapsacproject;
public class algorithm {


public native int [] geneticAlgorithm(int[] cost, int[] profit,int cmax, int gens, int turns);

static  {
try {
           System.load("C:/Users/Desktop/dp/KnapSacProject/src/knapsacproject/helo.dll");
  System.out.println("loaded successfully");
} catch (Exception e){
e.printStackTrace();
 }
 }
 protected int[] cost, profit, result;
 protected int gens, turns, cmax;

public algorithm(int[] cost,int[] profit, int gens ,int turns , int cmax ) {
this.cost=cost;
this.profit=profit;
this.gens=gens;
this.turns=turns;
  this.cmax=cmax;

    }

  public int[] getResult(){
 return geneticAlgorithm(cost,profit,gens,turns,cmax);
  }
  public static void main (String[] args ) {
     }
  }

那么如何返回多个值或如何解决此问题?

1 个答案:

答案 0 :(得分:1)

创建一个具有所需返回值数量的对象。使用所需的值创建新对象。返回对象。

相关问题