小编asl*_*oob的帖子

调用静态JNI方法从C++返回String

我试图在Android中调用以下java方法

public static String getLevelFile(String levelName) { /*body*/}
Run Code Online (Sandbox Code Playgroud)

从c ++使用以下jni代码

JniMethodInfoJavaApi methodInfo;

    if (! getStaticMethodInfo(methodInfo, "getLevelFile", "(Ljava/lang/String;)Ljava/lang/String;"))
        {
            return std::string("");
        }
    LOGD("calling getLevelFile");
    jstring returnString = (jstring) methodInfo.env->CallStaticObjectMethod(methodInfo.classID, methodInfo.methodID, levelName.c_str());
    LOGD("returned from getLevelFile");
    methodInfo.env->DeleteLocalRef(methodInfo.classID);

    const char *js = methodInfo.env->GetStringUTFChars(returnString, NULL);
    std::string cs(js);
    methodInfo.env->ReleaseStringUTFChars(returnString, js);
    LOGD("returning Level data");
Run Code Online (Sandbox Code Playgroud)

应用程序在执行此操作时崩溃CallStaticMethodObject().我通过使用验证了方法签名是正确的javap.而LOGD("calling getLevelFile");打印精细,然后它崩溃.我可以CallStaticVoidMethod()从同一个班级做其他的但不是这个.我有什么想法我做错了吗?

c++ java java-native-interface android android-ndk

6
推荐指数
2
解决办法
6225
查看次数

Android JNI中的Bogus方法描述符

我在Java中有以下类

package com.artifex.mupdf.data;

public class FzTextSpan {

FzRect bbox;
int len, cap;
FzTextChar[] mFzTextChars;
public FzTextSpan(FzRect bbox, int len, int cap, FzTextChar[] mFzTextChars) {
    super();
    this.bbox = bbox;
    this.len = len;
    this.cap = cap;
    this.mFzTextChars = mFzTextChars;
}
}
Run Code Online (Sandbox Code Playgroud)

我试图使用foll代码从JNI调用构造函数

jclass         jFzSpanClass;
jmethodID      jFzSpanCtor;

jFzSpanClass = (*env)->FindClass(env, "com/artifex/mupdf/data/FzTextSpan");
if (jFzSpanClass==NULL) return NULL;
jFzSpanCtor =  (*env)->GetMethodID(env, jFzSpanClass, "<init>",
   "(Lcom/artifex/mupdf/data/FzRect;II;[Lcom/artifex/mupdf/data/FzTextChar;)V");
Run Code Online (Sandbox Code Playgroud)

我正进入(状态

 Bogus Method Descriptor:        "(Lcom/artifex/mupdf/data/FzRect;II;[Lcom/artifex/mupdf/data/FzTextChar;)V");
Run Code Online (Sandbox Code Playgroud)

java java-native-interface android native

1
推荐指数
1
解决办法
2910
查看次数

标签 统计

android ×2

java ×2

java-native-interface ×2

android-ndk ×1

c++ ×1

native ×1