我在Java类中有一个返回整数的本机函数。函数定义在我的.c源文件中。尝试调用本机函数时,我的应用程序崩溃了。谁能告诉我哪里出错了?
java类:
package com.example.asish.fibseries;
/**
* Created by Asish on 2/9/2015.
*/
public class Fib {
public native static int NI(int n);
}
我的源文件(.c):
#include "com_example_asish_fibseries_Fib.h"
JNIEXPORT jint JNICALL Java_com_example_asish_fibseries_Fib_NI
(JNIEnv * env, jclass clazz, jint n){
jint previous = -1;
jint result = 1;
jint i;
for (i = 0; i < n; i++) {
jint sum = previous + result;
previous = result;
result = sum;
}
return result;
}
主要活动代码段:
public void onButtonClick(View v){
EditText e1;
e1 = (EditText) findViewById(R.id.editText);
TextView t1;
t1 = (TextView) findViewById(R.id.textView);
int n = Integer.parseInt(e1.getText().toString());
int y;
y = NI(n);
t1.setText(Integer.toString(y));
}
这是我们正在寻找的logcat吗?
---------主要开始 I / LoadedApk(12159):没有资源引用在包常见中更新 I / LoadedApk(12159):没有资源引用com.cyngn.yu包中的更新 I / LoadedApk(12159):没有资源引用com.cyngn.yu包中的更新 I / Timeline(12159):时间轴:Activity_idle id:android.os.BinderProxy@3d8f7182时间:33368817 I / Timeline(12159):时间轴:Activity_idle id:android.os.BinderProxy@3d8f7182时间:33404304 I / Timeline(12159):时间轴:Activity_launch_request id:org.jtb.alogcat time:33407440 I / Timeline(12159):时间轴:Activity_idle id:android.os.BinderProxy@2525babc时间:33407834 I / Timeline(12159):时间轴:Activity_idle id:android.os.BinderProxy@3d8f7182时间:33456683