RegisterNatives失败

时间:2014-03-21 02:03:18

标签: android java-native-interface

我有一个奇怪的问题,其中10个JNI函数中的9个工作正常,但是我刚添加的这个新的失败了。我试图在我的列表中移动这个函数,但它仍然失败了(方法II)

有什么想法吗?这是列表的样子:

static jboolean     JNICALL     Java_com_test_app_MyClass_JNI_AA(JNIEnv *env, jobject obj, jint iNum);
static jint         JNICALL     Java_com_test_app_MyClass_JNI_BB(JNIEnv *env, jobject obj);
static jobjectArray JNICALL     Java_com_test_app_MyClass_JNI_CC(JNIEnv *env, jobject obj, jint iNum);
static jint         JNICALL     Java_com_test_app_MyClass_JNI_DD(JNIEnv *env, jobject obj, jint iNum, jint x,    jint y, jint w, jint h);
static jint         JNICALL     Java_com_test_app_MyClass_JNI_EE(JNIEnv *env, jobject obj);
static jint         JNICALL     Java_com_test_app_MyClass_JNI_FF(JNIEnv *env, jobject obj, jboolean bOn);
static jint         JNICALL     Java_com_test_app_MyClass_JNI_GG(JNIEnv *env, jobject obj, jint iNum);
static jobjectArray JNICALL     Java_com_test_app_MyClass_JNI_HH(JNIEnv *env, jobject obj);
static jint         JNICALL     Java_com_test_app_MyClass_JNI_II(JNIEnv *env, jobject obj);
static jint         JNICALL     Java_com_test_app_MyClass_JNI_JJ(JNIEnv *env, jobject obj);

static JNINativeMethod gMethods[] = 
{
{"AA",      "(I)Z",                     (void *)&Java_com_test_app_MyClass_JNI_AA},
{"BB",          "()I",                      (void *)&Java_com_test_app_MyClass_JNI_BB},
{"CC",  "(I)[Ljava/lang/String;",   (void *)&Java_com_test_app_MyClass_JNI_CC},
{"DD",  "(IIIII)I",                 (void *)&Java_com_test_app_MyClass_JNI_DD},
{"EE",      "()I",                      (void *)&Java_com_test_app_MyClass_JNI_EE},
{"FF",          "(Z)I",                     (void *)&Java_com_test_app_MyClass_JNI_FF},
{"GG",          "(I)I",                     (void *)&Java_com_test_app_MyClass_JNI_GG},
{"HH",  "()[Ljava/lang/String;",    (void *)&Java_com_test_app_MyClass_JNI_HH},
{"II",      "()I",                      (void *)&Java_com_test_app_MyClass_JNI_II},
{"JJ",          "()I",                      (void *)&Java_com_test_app_MyClass_JNI_JJ},
};

当我调用env-> RegisterNatives(clazz,gMethods,sizeof(gMethods)/ sizeof(gMethods [0]))时,错误如下;

E/dalvikvm( 4573): ERROR: couldn't find native method
E/dalvikvm( 4573): Requested: Lcom/test/app/MyClass_JNI;.II:()I

我在这里缺少什么想法?

以下是该类的代码:

package com.test.app;

import android.util.Log;

public class MyClass_JNI 
{
    private static String LIB_NAME = "jni_test";

    static
    {
        System.loadLibrary(LIB_NAME);
    }

public native boolean AA(int pos);
public native int BB();
public native String[] CC(int pos);
public native int DD(int pos, int x, int y, int w, int h);
public native int EE();
public native int FF(boolean bIsFCCOn);
public native int GG(int iNum);
public native String[] HH();
public native int II();
public native int JJ();
}

3 个答案:

答案 0 :(得分:2)

做一个干净的&正如Robert H所建议的那样重建工作

答案 1 :(得分:0)

返回类型应为 jint 而不是 int

答案 2 :(得分:0)

我大多数情况下调用类的包和名称

  System.loadLibrary("so_name");

并且其方法必须与编译本机库的方法完全相同