-1

I wrote my code and i want return multiple values in :

public int[] getResult(){
return geneticAlgorithm(cost,profit,gens,turns,cmax);

but when i use this show me eror:

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)

my code :

 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 ) {
     }
  }

So How do I return multiple value or How do I fix this?

Meiko Rachimow
  • 4,664
  • 2
  • 25
  • 43
petko
  • 17
  • 2
  • 1
    That... doesn't even look like Java code, to me. I think you're sort of mixing up classes and functions, which Java keeps as two different domains... lines like this.cost will refer to the owning class. If you want to return multiple values, you either need to return a class that has those values as fields, or build an array of them (if they're of the same type.) – Edward Peters Mar 23 '16 at 21:51
  • 1
    If you want people to look at your code at least make some effort to format it in a readable manner. – Chris K Mar 23 '16 at 21:52
  • `native` tells me that it is probably platform dependent. Issue is, you haven't done anything that is platform dependent here. So why is it there? – Debosmit Ray Mar 23 '16 at 21:53
  • you should add your C implementation of "geneticAlgorithm" (helo.dll) to the question – Meiko Rachimow Mar 23 '16 at 21:53
  • Also. Love the function definition at the top. It's what you find in C, not Java. And there's no language called `Cava` (i think). – Debosmit Ray Mar 23 '16 at 21:56
  • Peace guys, I am a beginner in Java and this site is to help not only criticized ... thank you for the answers, I am very grateful for them :) – petko Mar 23 '16 at 22:01
  • Next time it will go better and I'm going to try your ideas – petko Mar 23 '16 at 22:02

1 Answers1

1

Make an object with the number of return values you need. Create a new object with those values that you want. Return the object.

Debosmit Ray
  • 5,228
  • 2
  • 27
  • 43
  • ok , i try thank you – petko Mar 23 '16 at 22:03
  • @petko let me know if you need help :) – Debosmit Ray Mar 23 '16 at 22:06
  • of course, thank you again – petko Mar 23 '16 at 22:14
  • @petko Sure :) It would be nice, if you could accept/upvote an answer if your issue is resolved. From [here](http://meta.stackexchange.com/questions/5234/how-does-accepting-an-answer-work), "Accepting an answer is important as it both rewards posters for solving your problem and informs others that your issue is resolved." – Debosmit Ray Mar 23 '16 at 22:15