当我在运行使用JNI函数和c++代码的安卓应用程序时,出现了错误。运行时,我看到了以下信息:
致命信号11(SIGSEGV)位于0xe480001d(code=1),线程5465
这是我的代码:
致命信号11(SIGSEGV)位于0xe480001d(code=1),线程5465
这是我的代码:
JNIEXPORT jstring JNICALL Java_ir_bassir_ndktest4_MainActivity_getName
(JNIEnv *env, jobject obj){
jclass cls = (*env)->GetObjectClass(env, obj);
jmethodID mid = (*env)->GetStaticMethodID(env, cls, "testJava", "([Ljava/lang/String)[Ljava/lang/String");
jstring plainText = (*env)->NewStringUTF(env, "Hello from JNI ! Compiled with ABI 2222 ");
jstring result = (*env)->CallStaticObjectMethod(env, cls, mid, plainText);
return (*env)->NewStringUTF(env, plainText);
}
在Java方面:
public class MainActivity extends ActionBarActivity {
public native String getName();
public static String testJava(String txt){
Log.d("BP","call back to java method");
String result = txt + "its added in JAVA";
return result;
}
static{
System.loadLibrary("HelloJNI");
}
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
String name = getName();
Log.d("BP",name);
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.menu_main, menu);
return true;
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
// Handle action bar item clicks here. The action bar will
// automatically handle clicks on the Home/Up button, so long
// as you specify a parent activity in AndroidManifest.xml.
int id = item.getItemId();
//noinspection SimplifiableIfStatement
if (id == R.id.action_settings) {
return true;
}
return super.onOptionsItemSelected(item);
}
}