【问题标题】:Android 4.0 Ice Cream Sandwich JNI jclass arg has wrong typeAndroid 4.0 Ice Cream Sandwich JNI jclass arg 类型错误
【发布时间】:2012-02-29 23:09:33
【问题描述】:

JNI 警告:jclass arg 类型错误(预期为 Ljava/lang/Class;,得到 Lcom/my/app/MyClass;) 在 Lcom/my/app/MyClass;.myMethod:()V (SetStaticIntField)

这是我的代码

static jclass   myObject = NULL;

static BOOL init(JNIEnv *env)
{
     jclass* localClass = (*env)->FindClass(env, "com/my/app/MyClass");
     myObject = (jclass*)(*env)->NewGlobalRef(env, localClass);
}

JNIEXPORT void JNICALL Java_com_my_app_MyClass_myMethod(JNIEnv *env, jobject obj)
{
        int position = getPosition(); /* the value is set at 1*/
    (*env)->SetStaticIntField(env, obj, position_field_id, position);
}

我的应用程序在 Android 2.1、2.1、2.3.x 中运行良好;但是当我在 Android 4.0 上使用它时,它会崩溃并显示我在开头提到的警告。

当我注释掉应用程序运行的行时,它可能会破坏其他内容。

尝试将 jobject 更改为 jclass 但不起作用。

感谢您的帮助

【问题讨论】:

    标签: java-native-interface android-4.0-ice-cream-sandwich


    【解决方案1】:

    我需要在 SetStaticField 上传递一个类而不是一个对象

    jclass cls = (*env)->GetObjectClass(env, obj);

    Android 4 似乎不喜欢 jni 警告

    【讨论】:

      猜你喜欢
      • 2012-03-01
      • 1970-01-01
      • 2012-05-17
      • 1970-01-01
      • 2012-03-02
      • 2012-04-01
      • 2012-05-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多