【问题标题】:Can JNI callback function use the class member?JNI回调函数可以使用类成员吗?
【发布时间】:2011-12-12 15:17:21
【问题描述】:

我想在函数 PrintLog() 中使用类成员“tvLog”,该函数将在 C++ 中的 JNI 中调用。但它导致了“正在关闭 VM.... FATAL EXCEPTION: main....”错误。谁能告诉我为什么?

simple_test.java:

public class simple_test extends Activity {
    private TextView tvLog = (TextView)findViewById(R.id.LogTextView);

    public int PrintLog(int i) {
        tvLog.setText("Log from JNI");
        return 0;
    }
}

demo_jni.cpp

...
mid = env->GetMethodID(cls, "PrintLog", "(I)I");
...
int ret = env->CallIntMethod(obj, mid, 1);
...

main.xml:

<TextView android:text="" android:layout_x="14dp" android:layout_y="147dp" android:layout_width="290dp" android:layout_height="98dp" android:id="@+id/LogTextView"></TextView>

【问题讨论】:

  • 完整的堆栈跟踪会很有帮助。
  • 如何获取cls对象?

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


【解决方案1】:

private TextView tvLog ==> static private TextView tvLog

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2010-11-03
    • 2016-03-08
    • 1970-01-01
    相关资源
    最近更新 更多