NewGlobalRef的jmethodID [英] NewGlobalRef for jmethodID

查看:1771
本文介绍了NewGlobalRef的jmethodID的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的东西,否则,似乎是一件容易的事的问题。 我有它返回一个Java类(自定义)的实例的jobjectArray一个本地方法。 我要做的就是让我想要实例并返回,然后得到jmethodID它的构造函数中JCLASS我的课。

I have a problem with something that otherwise seems to be an easy task. I have a native method which returns a jobjectArray of instances of a Java class (custom). What I do is get the jclass for my class I want to instantiate and return and then get the jmethodID for it's constructor.

本机方法的签名是:

JNIEXPORT jobjectArray JNICALL
Java_com_mn_rootscape_utils_NativeMethods_getFilesPermissions( JNIEnv* env, jobject thizz, jobjectArray filePathsArray ) 

命名空间和构造函数签名的定义如下:

The namespace and constructor signature are defined as follows:

const char* kFilePermissionInfoPath = "com/mn/rootscape/utils/FilePermissionInfo";
const char* kFilePermInfoConstructorSig = "(IIIIIJJJLjava/lang/String;Ljava/lang/String;ZLjava/lang/String;)V";

有关的JCLASS和jmethodID我下面的说明发布<一个href="http://android-developers.blogspot.ro/2011/11/jni-local-reference-changes-in-ics.html">here.所以我让他们的全局引用,这样我就可以在以后使用它们。 请注意,我没有在我的lib一个的OnInit然而,code是只是用于测试了。

For the jclass and jmethodID I'm following the instructions posted here. So I'm getting their global references so I can use them later. Please note that I do not have an oninit in my lib yet, the code is just for testing for now.

现在的问题是,我得到一个分段错误,当我尝试检索的jmethodID的全球参考。

The problem is that I get a segmentation fault when I try to retrieve the global reference for the jmethodID.

在code,这是否是:

The code that does this is:

jclass filePermInfoCls = (*env)->FindClass(env, kFilePermissionInfoPath);
if(!filePermInfoCls)
{
    LOGE("getFilesPermissions: failed to get class reference.");
    return NULL;
}

gFilePermInfoClass = (jclass)(*env)->NewGlobalRef(env, filePermInfoCls);
LOGI("got gFilePermInfoClass");

jmethodID filePermInfoClsConstructor = (*env)->GetMethodID(env, gFilePermInfoClass, "<init>", kFilePermInfoConstructorSig1);
if(!filePermInfoClsConstructor)
{
    LOGE("getFilesPermissions: failed to get method reference.");
    return NULL;
}

gFilePermInfoClsConstructor = (jmethodID)(*env)->NewGlobalRef(env, filePermInfoClsConstructor);
LOGI("got gFilePermInfoClsConstructor");

实际的错误是:

The actual error is:

九月6日至14日:17:26.648:W / dalvikvm(26012):无效的间接引用   0x4c0bdc40在德codeIndirectRef 9月6号至14日:17:26.648:E / dalvikvm(26012):   VM终止执行

06-14 09:17:26.648: W/dalvikvm(26012): Invalid indirect reference 0x4c0bdc40 in decodeIndirectRef 06-14 09:17:26.648: E/dalvikvm(26012): VM aborting

gFilePermInfoClass和gFilePermInfoClsConstructor是全球JCLASS和jmethodID对象,举行全球裁判。

gFilePermInfoClass and gFilePermInfoClsConstructor are global jclass and jmethodID objects, to hold the global refs.

任何帮助,这将是AP preciated。

Any help in this would be appreciated.

感谢

推荐答案

A jmethodID 不是一个对象。你并不需要将其转换为一个 GlobalRef 。同上 jfieldID

A jmethodID is not an object. You don't need to convert it to a GlobalRef. Ditto jfieldID.

这篇关于NewGlobalRef的jmethodID的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆