Android NDK:在方向更改时随机获得异常

时间:2015-03-03 11:25:52

标签: android eclipse android-ndk crash java-native-interface

我正在尝试实现初学者NDK应用程序。

程序运行并提供输出,但有时会改变方向,

它给出了错误

03-03 16:48:24.992: D/dalvikvm(21338): No JNI_OnLoad found in /data/app-lib/com.example.ndkdemo_scan-1/libnative.so 0x41fe7b90, skipping init

03-03 16:48:25.018: A/libc(21338): Fatal signal 11 (SIGSEGV) at 0x5f0f605c (code=2), thread 21338 (le.ndkdemo_scan)

我正在编写下面的代码:

#include <jni.h>
#include <stdio.h>
#include <string.h>

jstring Java_com_example_ndkdemo_scan_MainActivity_getString(JNIEnv * env,jobject object , jstring s){

    const char *string1  = (*env)->GetStringUTFChars(env,s,NULL);

    if(string1==NULL) return NULL;
    char *c = "input is :%s";
    printf(c,string1);
    char out[129];
    printf("Enter A String : ");
    scanf("%s",out);
    printf("String entered is :%s",out);

    strcat(string1,string1);

    jstring string_to_return = (*env)->NewStringUTF(env,string1);
    return string_to_return;
}

0 个答案:

没有答案