2

JNI を使用して C++ から Java にオブジェクトを渡しています。しかし、「GetMethodID」が常に NULL を返し、クラッシュするコードのどこかで立ち往生しています! 以下は、私が使用したヘッダー ファイルと、それに続く cpp コードです。

私の意図は、以下のcppコードで常に「emu_response_constructor Null」を取得するJNIからオブジェクトを返すことです。

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

#ifndef _Included_com_em_Grabber
#define _Included_com_em_Grabber
#ifdef __cplusplus
extern "C" {
#endif
/*
 * Class:     com_em_Grabber
 * Method:    getProcessedImage
 * Signature: (II[B)Lcom/em/Response;
 */
JNIEXPORT jobject JNICALL Java_com_em_Grabber_getProcessedImage
  (JNIEnv *, jobject, jint, jint, jbyteArray);

#ifdef __cplusplus
}
#endif
#endif

以下は、私が使用したcppファイルです。オブジェクトが Java に渡される場所。

JNIEXPORT jobject JNICALL Java_com_em_Grabber_getProcessedImage
  ( JNIEnv *env, jobject obj, jint jRows, jint jCols,jbyteArray jByteArray ){

         jclass emu_response = env->FindClass("com/em/Response");

         if (emu_response == NULL) {
             cout << "emu_response Null" << endl;
        }

         jmethodID emu_response_constructor = env -> GetMethodID(emu_response, "<init>", "(II[B)Lcom/em/Response;");
         if (NULL == emu_response_constructor ) {

             cout << "emu_response_constructor Null" << endl;

         }
   int number = 90;
   jobject jEmuResponse = env->NewObject ( emu_response,emu_response_constructor, jByteArray, number );

 return jEmuResponse;

}

以下は私のJavaクラスです:

public class Response {


    private int age;
    private byte[] result = null;


    public Response()
    {

    }
    public Response(byte[] result,int age) {
    this.age = age;
    this.result = result;
    }

    public int getAge() {
    return age;
    }
    public void setAge(int age) {
    this.age = age;
    }
    public byte[] getResult() {
    return result;
    }
    public void setResult(byte[] result) {
    this.result = result;
    }
4

1 に答える 1