GetMethodID落在android上

时间:2013-10-17 14:47:20

标签: java android c++ java-native-interface native

我正在尝试从C ++触发软输入,并且由于GetMethodID函数的丢失,我的应用程序崩溃了。

java类:

public class MyView extends SurfaceView implements SurfaceHolder.Callback {
    // ...
    public void toggleKeyboard() {
        Log.i("SurfaceView", "TOGGLE_KEYBOARD ---------------------");
        InputMethodManager imm = (InputMethodManager) getContext()
                .getSystemService(Context.INPUT_METHOD_SERVICE);
        imm.toggleSoftInput(InputMethodManager.SHOW_FORCED, 0);
    }
}

本机代码:

static JavaVM *jvm = 0;
static jobject surface;

JNIEXPORT void JNICALL Java_br_com_viewsample_NativeGlue_onStart(JNIEnv* jenv, jobject, jobject surfaceView)
{
    jint rs = jenv->GetJavaVM(&jvm);
    surface = jenv->NewGlobalRef(surfaceView);
}

void triggerSoftInput ()
{
  JNIEnv *env = 0;
  jint rs = jvm->GetEnv((void **) &env, JNI_VERSION_1_6);
  if (rs == JNI_OK)
      LOG_INFO("OK");
  else if (rs == JNI_EDETACHED) {
      LOG_INFO("EDETACHED");
      if (jvm->AttachCurrentThread(&env, NULL) < 0) {
          LOG_INFO("Failed to get the environment using AttachCurrentThread()");
       } else {
          // Success : Attached and obtained JNIEnv!
          LOG_INFO("success");
       }
  }
  else if (rs == JNI_EVERSION)
       LOG_INFO("EVERSION");
  else
       LOG_INFO("ELSE");

  jclass cls = env->GetObjectClass(surface);
  LOG_INFO("<< class");
  if (!cls) LOG_INFO("<< class FAIL");

  jmethodID m = env->GetMethodID(cls, "toggleKeyboard", "()V");
  LOG_INFO("<< method");
  if (!m) LOG_INFO("<< method FAIL");

  env->CallVoidMethod(surface, m);
  LOG_INFO("<< call");
};

日志:

I/ViewSample-Renderer(17130): Renderer::paint()
I/ViewSample-Renderer(17130): <><><><><><> MESSAGE RECEIVED!
I/ViewSample-JNI(17130): EDETACHED
I/ViewSample-JNI(17130): success
I/ViewSample-JNI(17130): << class
I/ViewSample-JNI(17130): << method
I/ViewSample-JNI(17130): << method FAIL
F/libc    (17130): Fatal signal 11 (SIGSEGV) at 0x00000004 (code=1), thread 17143 (com.viewsample)
I/DEBUG   ( 4864): *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** ***
I/DEBUG   ( 4864): Build fingerprint: 'Android/full_mako/mako:4.2.2/JDQ39/...:userdebug/test-keys'
I/DEBUG   ( 4864): Revision: '11'
I/DEBUG   ( 4864): pid: 17130, tid: 17143, name: com.viewsample  >>> br.com.viewsample <<<
I/DEBUG   ( 4864): signal 11 (SIGSEGV), code 1 (SEGV_MAPERR), fault addr 00000004
I/DEBUG   ( 4864):     r0 41508060  r1 00000000  r2 00000001  r3 40cac508
I/DEBUG   ( 4864):     r4 41d63dc8  r5 00000000  r6 72ff0718  r7 758d8cac
I/DEBUG   ( 4864):     r8 00000000  r9 00000000  sl 72388810  fp 00000041
I/DEBUG   ( 4864):     ip 00000000  sp 758d8c68  lr 40c4a31d  pc 40c69368  cpsr 60000030
I/DEBUG   ( 4864):     d0  6f6874656d203c64  d1  3b65636166727520
I/DEBUG   ( 4864):     d2  0000001400000346  d3  73a7108400000041
I/DEBUG   ( 4864):     d4  0054006500630061  d5  0075007400780065
I/DEBUG   ( 4864):     d6  0000000000650072  d7  0000002100000001
I/DEBUG   ( 4864):     d8  0000000000000000  d9  0000000000000000
I/DEBUG   ( 4864):     d10 0000000000000000  d11 0000000000000000
I/DEBUG   ( 4864):     d12 0000000000000000  d13 0000000000000000
I/DEBUG   ( 4864):     d14 0000000000000000  d15 0000000000000000
I/DEBUG   ( 4864):     d16 0000000000000001  d17 0000000000000001
I/DEBUG   ( 4864):     d18 0000000000000000  d19 bf5ce55c8eac7900
I/DEBUG   ( 4864):     d20 0000000000000000  d21 0000000000000000
I/DEBUG   ( 4864):     d22 0000000000000000  d23 0000000000000000
I/DEBUG   ( 4864):     d24 3f65555555555555  d25 0000000000000000
I/DEBUG   ( 4864):     d26 4000000000000000  d27 0000000000000000
I/DEBUG   ( 4864):     d28 0000000000000000  d29 0000000000000000
I/DEBUG   ( 4864):     d30 0000000000000000  d31 0000000000000000
I/DEBUG   ( 4864):     scr 60000092
I/DEBUG   ( 4864): 
I/DEBUG   ( 4864): backtrace:
I/DEBUG   ( 4864):     #00  pc 0006b368  /system/lib/libdvm.so (deleted)
I/DEBUG   ( 4864):     #01  pc 00005c44  <unknown>

我遇到了这次崩溃。你能帮我调查一下吗?

0 个答案:

没有答案