私はJavaでndkを実行していますが、logcatでこれらのエラーが発生しました。
11-02 12:36:43.582: E/Trace(717): error opening trace file: No such file or
directory (2)
11-02 12:36:43.902: D/dalvikvm(717): Trying to load lib
/data/data/com.example.hellojni/lib/libhello-jni.so 0x411e35b8
11-02 12:36:43.918: D/dalvikvm(717): Added shared lib
/data/data/com.example.hellojni/lib/libhello-jni.so 0x411e35b8
11-02 12:36:43.918: D/dalvikvm(717): No JNI_OnLoad found in
/data/data/com.example.hellojni/lib/libhello-jni.so 0x411e35b8, skipping init
11-02 12:36:43.953: W/dalvikvm(717): Invalid indirect reference 0x2a00b9e0 in
decodeIndirectRef
11-02 12:36:43.953: E/dalvikvm(717): VM aborting
11-02 12:36:43.953: A/libc(717): Fatal signal 11 (SIGSEGV) at 0xdeadd00d (code=1),
thread 717 (xample.hellojni)
私のJavaとネイティブコードはこのようなものです。ネイティブスペースで2つの配列要素の追加を実行したいと思います。
JAVAコード
package com.example.hellojni;
import android.app.Activity;
import android.widget.TextView;
import android.os.Bundle;
public class HelloJni extends Activity{
public native double[] additionfromJNI(double[] array1,double[] array2);
double matrix1[] = new double[4];
double matrix2[] = new double[4];
double matrix3[] = new double[4];
String matrix4 = "";
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
TextView tv = new TextView(this);
for(int i=0;i<4;i++){
matrix1[i]=1.0;
matrix2[i]=2.0;
}
matrix3= additionfromJNI(matrix1,matrix2);
for(int i=0;i<4;i++){
matrix4= matrix4+ Double.toString(matrix3[i])+",";
}
tv.setText(matrix4);
setContentView(tv);
}
static {
System.loadLibrary("hello-jni");
}
}
ネイティブコード
#include <string.h>
#include <jni.h>
jdoubleArray
Java_com_example_hellojni_HelloJni_additionfromJNI
( JNIEnv* env,jobject thiz, jdoubleArray mat1 ,jdoubleArray mat2 )
{
jboolean isCopy1;
jboolean isCopy2;
jsize length= 16;
jint i=0;
jdouble *result;
jdouble* srcArrayElems1 = (*env)->GetDoubleArrayElements(env,mat1, &isCopy1);
jint n = (*env) -> GetArrayLength(env,mat1);
jdouble* srcArrayElems2 = (*env)->GetDoubleArrayElements(env,mat2, &isCopy2);
for(i=0; i<n; i++){
result[i]=srcArrayElems1[i]+srcArrayElems2[i];
}
if (isCopy1 == JNI_TRUE) {
(*env) -> ReleaseDoubleArrayElements(env,mat1, srcArrayElems1,
JNI_ABORT);
}
if (isCopy2 == JNI_TRUE) {
(*env) -> ReleaseDoubleArrayElements(env,mat2, srcArrayElems2,
JNI_ABORT);
}
return result;
}
誰かが私がこれらの問題を解決するのを手伝ってくれる?