异常 - 错误本机方法 - 签名

时间:2016-03-19 12:48:42

标签: java exception methods java-native-interface native

我创建程序,我使用本机库但它显示错误。我不懂为什么。也许与签名

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:37)
    at knapsacproject.Interface.jButton4ActionPerformed(Interface.java:209)
    at knapsacproject.Interface.access$300(Interface.java:15)
    at knapsacproject.Interface$4.actionPerformed(Interface.java:94)

knapsacproject_algorithm.h

/* DO NOT EDIT THIS FILE - it is machine generated */
#include <jni.h>
/* Header for class knapsacproject_algorithm */

#ifndef _Included_knapsacproject_algorithm
#define _Included_knapsacproject_algorithm
#ifdef __cplusplus
extern "C" {
#endif
/*
 * Class:     knapsacproject_algorithm
 * Method:    geneticAlgorithm
 * Signature: ([I[IIII)[I
 */
JNIEXPORT jintArray JNICALL Java_knapsacproject_algorithm_geneticAlgorithm
  (JNIEnv *, jobject, jintArray, jintArray, jint, jint, jint);

#ifdef __cplusplus
}
#endif
#endif

galib.c ----然后是本机库HelloWorld.dll

#include <jni.h>
#include "knapsacproject_algorithm.h"
#include "gaParameters.h"
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include <time.h>


JNIEXPORT jintArray JNICALL Java_knapsacproject_algorithm_geneticAlgorithm 
(JNIEnv * , jobject , jintArray, jintArray , jint, jint, jint);

void ga_solve(int * result, int * CostT, int * ProfitT, int Cmax, int GENS, int TURNS, int size) {


algorithm.java

algorithm.java - 它加载C les来计算和解决问题。

package knapsacproject;
import java.io.IOException;

public class algorithm {

    /**
     *
     * @param cost
     * @param profit
     * @param cmax
     * @param gens
     * @param turns
     * @return
     */
    public native int [] geneticAlgorithm(int[] cost, int[] profit, int gens, int turns,int cmax);
    static  {

        System.load("C:/Users/Desktop/dp/KnapSacProject/src/knapsacproject/HelloWorld.dll");
        System.out.println("loaded successfully");


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

Interface.java

import knapsacproject.algorithm;
import javax.swing.table.DefaultTableModel;


public class Interface extends javax.swing.JFrame {

    /**
     * Creates new form Interface
     * @param cost
     * @param profit
     * @return 
     */
public native double[] geneticAlgorithm(int[] cost, int[] profit);

public Interface() {
initComponents();

    }

.......

0 个答案:

没有答案